首页  >  文章  >  后端开发  >  php如何解决回车换行符的转换问题

php如何解决回车换行符的转换问题

coldplay.xixi
coldplay.xixi原创
2020-09-30 09:29:544682浏览

php解决回车换行符转换的方法:1、使用file函数,代码为【$list = file($intstr)】;2、使用replace函数,代码为【ereg_replace("\r\n", "", $value);】。

php如何解决回车换行符的转换问题

php解决回车换行符转换的方法:

方法 1  :nl2br(PHP 4, PHP 5)

nl2br — Inserts HTML line breaks before all newlines in a string

方法2:可以采用file()函数,例子如下

function fmtfilenl($intstr)
{
 $list = file($intstr);
 foreach($list as $row) {
    $outstr=$outstr.$row.'
';
 }
 return $outstr;
}

方法3:

$a = preg_replace("/[\r\n]+/", ',', $a);或$a = join(',', split("[\r\n]+", $a));

方法4:

ereg_replace("\r\n", "", $value);

最后一个知道的,PHP code

str_replace("\n", '', str_replace("\r\n", "\n", $a));
or
str_replace(PHP_EOL, "\n", $a )

想了解更多编程学习,敬请关注php培训栏目!

以上是php如何解决回车换行符的转换问题的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn