Posted By

sublimino on 09/02/08


Tagged

regex strip space


Versions (?)

all spaces become single spaces regex


 / Published in: PHP
 

  1. $test = '23 124 124 4 2 21 4 142 lajdlkajsldkajs jasd 124 what great data t a a';
  2. $test = preg_replace( '([\ ])', ' ', $test );
  3. echo $test;

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Scooter on September 7, 2008

That pattern also catches dollar signs, hyphens, and round brackets, none of which are whitespace. A better pattern would be '[\s]{2,}'.

Posted By: sublimino on September 23, 2008

I'm not sure if '[\s]{2,}' is php compatible - the above snippet has been amended slightly

You need to login to post a comment.