Page 1 of 1

Trying to get rid of all space and tab characters

Posted: Wed Sep 27, 2006 5:12 pm
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 :)

Posted: Wed Sep 27, 2006 5:30 pm
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.

Posted: Wed Sep 27, 2006 5:38 pm
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 :)