Remove excess whitespaces from string / Remove espaços em excesso de uma string


/ Published in: PHP
Save to your folder(s)

Remove excess whitespaces from string
Remove espaços em branco em excesso de uma string


Copy this code and paste it in your HTML
  1. function stripExcessSpaces($str)
  2. {
  3. return preg_replace('/\s\s+/', ' ', $str);
  4. }
  5.  
  6. // ex.:
  7. $string = 'String with too many whitespaces.';
  8. echo '<pre>'.$string."
  9. ".stripExcessSpaces($string).'</pre>';

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.