strip whitespace?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

strip whitespace?

Post by Pyrite »

Ok, I know about trim(), ltrim() and rtrim(). But is there a way to just strip ALL whitespace from a string?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

preg_replace(), str_replace() :?

take your pick, I would probably use str_replace since this a real simple and regex would be overkill

something along the lines of

Code: Select all

$str = str_replace(" ","",$str);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. since you say whitespace..

Code: Select all

$str = preg_replace('#\s+#s', '', $str);
Post Reply