[solved] removing spaces

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
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

[solved] removing spaces

Post by irealms »

Is str_replace the best way of removing a space from a number or text?
Last edited by irealms on Tue Jan 18, 2005 6:26 am, edited 1 time in total.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

It's one way. You could also use trim() if you know the whitespace is at the beginning or end. Regular expressions might be a second option. preg_replace(). I'd use str_replace() before preg_replace().
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post by irealms »

Yeah the space is in the middle, i'll stick to str_replace, thanks. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a preg_replace example of removing spaces can be found here:

viewtopic.php?t=29465
Post Reply