Php fwrite txt problem

Hello,

Does anyone know a reason why when I write a string to a txt file such as:

"The Mars Volta
"

It literally writes the ’
’ instead of creating a new line? The server is a unix server.

Or you could write:


fputs($fp, 'The mars volta' . chr(10));

I wouldn’t use chr(10).

A) It’s almost certainly slower

B) and more importantly, it’s not obvious to anyone looking at the code

Also, you may be better off using PHP_EOL if the source of the files is the same as the operating system you are working with.

edit: Oh and The Mars Volta :tup:

Thank you, the quote problem fixed it. I didn’t realize there was a real difference.

or you can keep it your way but would need to include extra quotes


fputs($fp, 'The mars volta' . "\
");

Looks like you’re using single quotes to write the string


$fp = fopen('some_file', 'w');
fputs($fp, 'The mars volta\
');
fclose($fp);

In which case
won’t be evaluated to a line break which will indeed result in
be put in the file literally. The fix for this is to use a double quoted string, i.e,


$fp = fopen('some_file', 'w');
fputs($fp, "The mars volta\
");
fclose($fp);

If what I described above is not the case, could you post the complete code?