Posted By

rafaelmt on 01/29/08


Tagged

regex php String sanitize


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

bsisco


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


 / Published in: PHP
 

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

  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
Posted By: tobiwan on January 31, 2008
echo '<pre>'.$string."\r\n".stripExcessSpaces($string).'</pre>';
Posted By: rafaelmt on February 5, 2008

thanks for the correction, tobiwan

You need to login to post a comment.