Im writing to a file using php, and i have no idea why i开发者_如何学Cn the text file the "\n" special character is not creating a newline, why?
Note that \n
doesn't always imply a newline :
- UNIX / Linux use
\n
(Newline) for linebreaks - Mac (before OSX) used
\r
(Carriage return) - And windows uses a combinaison of both
Also note that those \n
and \r
characters will work in double-quoted strings -- but not in single-quoted strings.
I would suggest you to use constant PHP_EOL instead of \n
. PHP_EOL should be used to find the newline character in a cross-platform-compatible way, so it handles DOS/Mac/Unix issues.
i had the same until i realized that
'\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
精彩评论