替换   带有空白或空字符串 PHP

San*_*rst 3 php str-replace

好吧,我已经尝试过这些,但似乎它们都不起作用,我的示例字符串是

 $text_description="       Hello world! lorel ipsum";

 $text_description= str_replace(" "," ",$text_description);
 $text_description = preg_replace("/&#?[a-z0-9]+;/i"," ",$text_description);
 $text_description=html_entity_decode($text_description);
Run Code Online (Sandbox Code Playgroud)

Mic*_*son 5

$text_description="       Hello world! lorel ipsum";
$text_description = str_replace(' ', ' ', $text_description);
echo $text_description;
Run Code Online (Sandbox Code Playgroud)

输出:

你好,世界!洛雷尔 ipsum