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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php