Replace excess whitespaces and line-breaks with PHP?

后端 未结 10 1748
你的背包
你的背包 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:14

    why you are doing like this?
    html displays only one space even you use more than one space...

    For example:

    test               content 1       2 3 4            5
    

    The output willl be:
    test content 1 2 3 4 5

    if you need more than single space in html, you have to use  

提交回复
热议问题