tags:

views:

20

answers:

1

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 protected];

But I'm getting

e-mail\[email protected];

How do I fix this?

+3  A: 

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.

codaddict
i agree with that. but i have one addition: depengin on the OS you are using you might have to consider using \r and/or \n\r
ITroubs
in Windows it is now printing `[email protected];`
Rodrigo Alves
try using `\r\n` in place of `\n'
codaddict
Or use the `PHP_EOL` constant, it will know your OS...
Wrikken