Skip to content
Advertisement

PHP Linefeeds (n) Not Working

For some reason I can’t use n to create a linefeed when outputting to a file with PHP. It just writes “n” to the file. I’ve tried using “\n” as well, where it just writes “n” (as expected). But I can’t for the life of me figure out why adding n to my strings isn’t creating new lines. I’ve also tried rn but it just appends “rn” to the line in the file.

Example:

error_log('testn', 3, 'error.log');
error_log('test2n', 3, 'error.log');

Outputs:

testntest2n

Using MAMP on OSX in case that matters (some sort of PHP config thing maybe?).

Any suggestions?

Advertisement

Answer

Use double quotes. "testn" will work just fine (Or, use 'test' . PHP_EOL).

If the string is enclosed in double-quotes (“), PHP will interpret more escape sequences for special characters:

http://php.net/manual/en/language.types.string.php

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement