且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用PHP编写TXT文件,想要添加实际的换行符

更新时间:2023-12-04 13:57:58

给我的声音就像您可能使用单引号一样,即'\n'而不是"\n".

Sounds to me like you might be using single quotes, i.e. '\n' rather than "\n".

如果您想继续使用单引号偏差(如您所愿!),则有两个选择:

If you wanted to continue with a single quotes bias (as you should!), two options:

file_put_contents('/path/to/file.txt', 'Hello friend!
This will appear on a new line.
As will this');

// or

file_put_contents('/path/to/file.txt', 'Hello friend!'."\n".'This will appear on a new line.'."\n".'As will this');