本教程操作环境:windows7系统、php7.1版,dell g3电脑
php替换换行符的方法:
$str="this is a test \n";
方法一:
$replace_str = str_replace(array("\r\n", "\r", "\n"), "", $str);
(注意:先替换掉\r\n,然后是否存在\n,最后替换\r)
方法二:
$replace_str = preg_replace('/[\r\n]/', '', $str);
(原文写的是/\s*/,但是这样会把内容里的空白字符也替换掉)
方法三:
$replace_str = str_replace(php_eol, '', $str);
推荐学习:《php视频教程》
以上就是php怎么将换行符替换掉的详细内容。
