Php替换回车的方法:1。替换为str_replace方法;2.使用preg_replace方法实现替换;3.Pass "str_replace(PHP_EOL,& # 39;',$ str);"语句可以替换。
本文操作环境:windows7系统,PHP 7.1版,DELL G3电脑
用PHP替换回车和换行的三种方法
一个小换行符在不同的平台上有不同的实现。为什么?世界是多样的!
最初,在Unix世界中,/n被用来代替包装,
Windows使用/r/n来显示差异。
更有意思的是,Mac里又用上了/r。
所以在不同平台上写程序有很多麻烦,比如替换断行。
第一条路
str_replace(数组(& quot/r & quot;,& quot/n & quot;,& quot/r/n"。),& quot",$ string);第二种方法是使用正则表达式
$ str = preg _ replace(& # 39;//s */& # 39;, '',$ str);第三条路
在这里,我必须重新审视php中定义的变量
PHP_EOL就是其中之一,代表PHP的新行符。这个变量会根据平台而变化。在windows中是/r/n,在linux中是/n,在mac中是/r
$str = str_replace(PHP_EOL,& # 39;',$ str);【推荐学习:《php视频教程》】以上是PHP如何取代回车的细节,更多