hankknight
asked on
mySQL: Multiple Replace
I use the following PHP / mySQL code to search for matches after removing spaces. Now I want to remove multiple characters, not just spaces:
!+$*-.?,';_()
I can do this in PHP like this:
str_replace(array('!', '+', '$', '*', '-', '.', '?', ',', \''', ';', '_', '(', ')' )','',$term)
But how can I do this with mySQL?
!+$*-.?,';_()
I can do this in PHP like this:
str_replace(array('!', '+', '$', '*', '-', '.', '?', ',', \''', ';', '_', '(', ')' )','',$term)
But how can I do this with mySQL?
$query = "select `name` from `organizations` where replace(`name`, ' ', '') LIKE '%". str_replace(' ','',$term) . "%'";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you might consider to create a second column clean_name in your table, and have the "cleaned" value there, so you don't need to do this all the time, and you could even profit from an index on the field.-..
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
preg_replace( pattern, replacement, subject ,[limit])
preg_replace("/!+$*-.?,';_ ()/", '',STRING)
Ref: http://www.webcheatsheet.com/php/regular_expressions.php#replace
preg_replace("/!+$*-.?,';_
Ref: http://www.webcheatsheet.com/php/regular_expressions.php#replace