开发者

Removing more than one white-space

So, If I have a string like

"hello    what is  my    name"

How can I take all of the spaces and re开发者_Python百科place each with only one space?


This should do it:

$replaced = preg_replace('/\s\s+/', ' ', $text);

Output:

hello what is my name


Found the solution:

<?php

$str = ' This is    a    test   ';
$count = 1;
while($count)
    $str = str_replace('  ', ' ', $str, $count);

?>


Try this:-

$desc = "hello    what is  my    name";
echo trim(preg_replace('/\s+/', ' ', $desc));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜