I am using the PHP code:
$numberNewline = $number . '\n'; fwrite($file, $numberNewline);
to write $number to a file.
For some reason \n appears in the file. I am on a mac. What might be the problem?
Answer: Use the Newline Characters ' \n ' or ' \r\n ' You can use the PHP newline characters \n or \r\n to create a new line inside the source code. However, if you want the line breaks to be visible in the browser too, you can use the PHP nl2br() function which inserts HTML line breaks before all newlines in a string.
The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.
Answer: In PHP to echo a new line or line break use '\r\n' or '\n' or PHP_EOL. '\n' or '\r\n' is the easiest way to embed newlines in a PHP string. Also, '\n' can be used to create line breaks when creating PHP text files.
'\n'
in single quotes is a literal \n
."\n"
in double quotes is interpreted as a line break.
http://php.net/manual/en/language.types.string.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With