PHP New line character Windows vs. Macintosh

邮差的信 提交于 2019-12-10 20:56:05

问题


For a user input I do this: $var=str_replace(array('\r','\n'),'',$var);

Works well on Windows, removing any new lines. However, on the Mac (+Firefox) it somehow replaces the new lines with a \ character.

Any clues as to why that happens?


回答1:


I'm surprised it works on Windows.

Usually, for PHP to interpret control characters, they need to be in double-quoted strings, eg

array("\r", "\n")



回答2:


set the value auto_detect_line_endings to on in php.ini file or ini_set("auto_detect_line_endings", true);



来源:https://stackoverflow.com/questions/5830627/php-new-line-character-windows-vs-macintosh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!