用PHP编写TXT文件,想要添加实际的换行符 [英] Writing TXT File with PHP, Want to Add an Actual Line Break
问题描述
我正在使用PHP编写TXT文件.我想在必要时将实际的换行符插入TXT文件.我已经尝试了\ n \ r \ r \ n \ n \ r ...的所有组合,但是这些组合不会导致出现换行符-在大多数情况下,我看到文本"\ n"出现在TXT文件中,没有换行符.
I am writing a TXT file using PHP. I want to insert actual line breaks into the TXT file wherever necessary. I have tried all combinations of \n \r \r\n \n\r ... but these are not causing any linebreaks to appear - in most cases, I am seeing the text "\n" appear in the TXT file, with no linebreak.
我也尝试过chr(13).
I have also tried chr(13).
任何其他想法将不胜感激.
Any other ideas would be appreciated.
推荐答案
给我的声音就像您可能使用单引号一样,即'\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');
这篇关于用PHP编写TXT文件,想要添加实际的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!