Replace excess whitespaces and line-breaks with PHP?

后端 未结 10 1756
你的背包
你的背包 2020-12-07 20:25
$string = \"My    text       has so    much   whitespace    




Plenty of    spaces  and            tabs\";

echo preg_replace(\"/\\s\\s+/\", \" \", $string);
         


        
10条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 21:19

    Replace Multiple Newline, Tab, Space

    $text = preg_replace("/[\r\n]+/", "\n", $text);
    $text = preg_replace("/\s+/", ' ', $text);
    

    Tested :)

提交回复
热议问题