开发者

PHP New line character Windows vs. Macintosh

开发者 https://www.devze.com 2023-03-01 17:59 出处:网络
For a user input I do this: $var=str_replace(array(\'\\r\',\'\\n\'),\'\',$var); Works well on Windows, removing any new lines.

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 \ 开发者_StackOverflow中文版character.

Any clues as to why that happens?


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")


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

0

精彩评论

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

关注公众号