【发布时间】:2012-01-24 04:11:18
【问题描述】:
如何转$string:
"one two three"
进入:
"one two three"
?
【问题讨论】:
标签: php
如何转$string:
"one two three"
进入:
"one two three"
?
【问题讨论】:
标签: php
$str = "one two three";
$str = preg_replace('/ +/',' ',$str);
这会将一个或多个空格替换为一个空格。它也会用自己替换一个空格!!稍微改进一下:
$str = preg_replace('/ {2,}/',' ',$str);
用单个空格替换一组 2 个或多个连续空格。
【讨论】:
preg_replace('/s+/',' ',$str);会好一点。
试试这个:
$str = preg_replace("/[ ]{2,}/", " ", $str);
【讨论】: