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
.
精彩评论