Trying to get rid of all space and tab characters

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
Matt Langley
Forum Newbie
Posts: 2
Joined: Wed Sep 27, 2006 5:08 pm
Location: Eugene, OR

Trying to get rid of all space and tab characters

Post by Matt Langley »

Right now I'm using a standalone php binary to generate files for a look up table on some standalone docs... though that isn't the part I'm having troubles with.

I'm trimming all extra spaces and tab characters with trim() and rtrim()... it does a decent job, however I still get some random tab and/or space character spam, anyone else run into this and know what the problem is and maybe a way to fix it ?

This is somewhat detrimental since I am scanning a mass ammount of html files and generating a lookup table based on single words, so sometimes I get an entry with a massive ammount of either tabs or spaces in them that slipped through the trimming process.

Any help would be appreciated :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Where, by chance, are these "random tab and/or space character spam" events happen in a given piece of text? trim() and it's siblings do not remove data from the middle of a piece of text. If you need such functionality, I'd suggest using a regular expression (or str_replace()) as appropriate.
Matt Langley
Forum Newbie
Posts: 2
Joined: Wed Sep 27, 2006 5:08 pm
Location: Eugene, OR

Post by Matt Langley »

Thanks, especially for such a quick reply. For some reason I didn't think to check for the regular expressions in string replace. I had quite a long list of things I was replacing so added them to it and cleaned it right up, thx :)
Post Reply