To remove extra spaces from a string

$string = preg_replace('/\s+/', ' ', $stringWithSpaces);

 

Categorized in: