开发者

fwrite doesn't break the line

I'm writing this:

 $fh = fopen('public/newsletter.txt', 'w');
 foreach($entries as $row) {
        fwrite($fh, 'e-mail\n');
        fwrite($fh, $row->new_email . ';');
 }
 fclose($fh);

Expecting it to be

email
email@example.com开发者_StackOverflow社区;

But I'm getting

e-mail\nemail@example.com;

How do I fix this?


Use double quotes in place of single quotes.

fwrite($fh, "e-mail\n");
            ^        ^

The char combination \n is treated as a newline when it's inside double quotes. But when inside single quotes it's not treated and letter \ followed by n.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜