Re: Removing special chars
| From: | Jochem Maas | Date: | Sun, 30 Apr 2006 16:04:57 +0000 |
| Subject: | Re: Removing special chars | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235156@lists.php.net to get a copy of this message | ||
Gerry Danen wrote:
I would like to replace all chars in a string that are not a-z or 0-9 with a space. I can use a series of str_replace functions, but there has to be a faster way. I know there is a solution but my chemo-brain is slowing me down today. Sorry...$output = preg_replace('#[^a-z0-9]#i', '', $input); I always forget what the 'special' 'shortcut' tokens are for specifing alphanumeric chars, etc in regexps so I mostly end up writing it the long way round (as above). and as someone else mentioned str_replace (and preg_replace) can take arrays of strings for the find and replace args which save you doing multiple calls - although to what extent this is true is, I believe, dependant on your php version (check the docs for the specifics)
Any suggestions? TIA Gerry