So, If I have a string like
"hello what is my name"
How can I take all of the spaces and replace each with only one space?
Thanks!
So, If I have a string like
"hello what is my name"
How can I take all of the spaces and replace each with only one space?
Thanks!
Found the solution:
<?php
$str = ' This is a test ';
$count = 1;
while($count)
$str = str_replace(' ', ' ', $str, $count);
?>
This should do it:
$replaced = preg_replace('/\s\s+/', ' ', $text);
Output:
hello what is my name