开发者

fwrite doesn't break the line

开发者 https://www.devze.com 2023-01-18 23:54 出处:网络
I\'m writing this: $fh = fopen(\'public/newsletter.txt\', \'w\'); foreach($entries as $row) { fwrite($fh, \'e-mail\\n\');

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

精彩评论

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