Php fwrite不';不要越界
我在写这个:Php fwrite不';不要越界,php,string,newline,fwrite,Php,String,Newline,Fwrite,我在写这个: $fh = fopen('public/newsletter.txt', 'w'); foreach($entries as $row) { fwrite($fh, 'e-mail\n'); fwrite($fh, $row->new_email . ';'); } fclose($fh); 希望是 email email@example.com; 但是我越来越 e-mail\nemail@example.com; 如何解决此问题
$fh = fopen('public/newsletter.txt', 'w');
foreach($entries as $row) {
fwrite($fh, 'e-mail\n');
fwrite($fh, $row->new_email . ';');
}
fclose($fh);
希望是
email
email@example.com;
但是我越来越
e-mail\nemail@example.com;
如何解决此问题?使用双引号代替单引号
fwrite($fh, "e-mail\n");
^ ^
字符组合
\n
在双引号内时被视为换行符。但是,当在单引号内时,它不被处理,字母\
后跟n
我同意这一点。但我有一个补充:在使用的操作系统上的DeEnin可能需要考虑使用\R和/或\N\RINN窗口,它现在正在打印<代码>mailemail@example.com;代码>尝试使用\r\n
代替“\n”