PHP换行符Windows与Macintosh [英] PHP New line character Windows vs. Macintosh

查看:163
本文介绍了PHP换行符Windows与Macintosh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于用户输入,我这样做: $var=str_replace(array('\r','\n'),'',$var);

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

在Windows上运行良好,删除所有新行. 但是,在Mac(+ Firefox)上,它以某种方式用\字符替换了新行.

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?

推荐答案

我很惊讶它可以在Windows上运行.

I'm surprised it works on Windows.

通常,要让PHP解释控制字符,它们必须用双引号引起来,例如

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

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

这篇关于PHP换行符Windows与Macintosh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆