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);
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。