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));
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论