$string = "
put returns between paragraphs

for linebreak add 2 spaces at end

";

想从字符串中删除所有新行。

我有这个正则表达式,它可以捕获所有的,问题是我不知道该用哪个函数来使用它。

/\r\n|\r|\n/

$string应该变成:

$string = "put returns between paragraphs for linebreak add 2 spaces at end ";

当前回答

以下代码工作所有文本请使用它:

$des = str_replace('\n',' ',$des);
$des = str_replace('\r',' ',$des);

其他回答

$string = str_replace(array("\n", "\r"), ' ', $string);

文本中的换行符通常表示为:

\r\n -在Windows电脑上

\r -在苹果电脑上

\n - Linux

//Removes all 3 types of line breaks

$string = str_replace("\r", "", $string);

$string = str_replace("\n", "", $string);

非常简单的

$hello = "
A
B
C
";
str_replace("
", " ", $hello);
// A B C

这个选项也会删除制表符

$string = preg_replace('~[\r\n\t]+~', '', $text);

也许这样行得通:

$str='\n';
echo str_replace('\n','',$str);