Question

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;

But I'm getting

e-mail\nemail@example.com;

How do I fix this?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top