开发者

why isn't the \n special character not creating a new line in txt file using php

开发者 https://www.devze.com 2023-02-22 03:31 出处:网络
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 :

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

0

精彩评论

暂无评论...
验证码 换一张
取 消