zeroblitzt Posted August 4, 2006 Share Posted August 4, 2006 Hey all, i'm a total regex beginner (never used it), but someone recommended that I use it. What I need to do with it is remove excess spaces from a string (for my message boards).So if I were to have, say:[pre]Hello Everyone[/pre]it would shorten it down to[pre]Hello Everyone[/pre]I'm not sure how to go about doing it though. Any tips? Quote Link to comment Share on other sites More sharing options...
xec Posted August 5, 2006 Share Posted August 5, 2006 its very easy ,(\040)+ -- this is the meta character represent space.. and + sign represent if you want to remove multiple spaces. ;) Quote Link to comment Share on other sites More sharing options...
boby Posted August 5, 2006 Share Posted August 5, 2006 You can use this little preg_replace:[code=php]<?php$string = trim (preg_replace ('`[\s]+`', ' ', $string));?>[/code]Hope it helps ;)Boby Quote Link to comment Share on other sites More sharing options...
zeroblitzt Posted August 5, 2006 Author Share Posted August 5, 2006 Wow thanks for the help! I'll put you both in the credits of my source code :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.