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));
精彩评论