P PHP remove extra spaced from a string 1 Min Read 0 8 To remove extra spaces from a string $string = preg_replace('/\s+/', ' ', $stringWithSpaces); Categorized in: PHP Tagged in: PHP remove extra spaced from a string Share Article: