How to remove excess whitespace in a paragraph?

 $string = "There   are lot of excess space   in  this paragraph. "; 
How can you  remove them easily using a regular expression ?

Default Asked on June 15, 2016 in PHP.
Add Comment
  • 1 Answer(s)
    $string = preg_replace('/\s\s+/', ' ', $string);


    Default Answered on June 15, 2016.
    Add Comment

    Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.