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? Link to comment https://forums.phpfreaks.com/topic/16598-removing-excess-spaces/ 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. ;) Link to comment https://forums.phpfreaks.com/topic/16598-removing-excess-spaces/#findComment-69643 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 Link to comment https://forums.phpfreaks.com/topic/16598-removing-excess-spaces/#findComment-69800 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 Link to comment https://forums.phpfreaks.com/topic/16598-removing-excess-spaces/#findComment-69974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.