php - Regular expression to change user input -
I am searching on my database if the user enters the example "Foo bar" I want to display those lines I am both in "foo" and "bar"
My SQL syntax looks like this: SELECT * FROM t1 WHERE MATCH (t1.foo_desc, t2.bar_desc) ('+ Foo * + bar *')
I How can I change user input "foo bar" to "+ foo * + bar *" by using a regular expression?
It assumes that the input is not empty string;
EDIT: As @BurT S, str_replace (or mb_str_replace if you are working with multibyte characters) will also be simpler ...
$ match = '+' Str_replace ('', '* +', $ input). '*';
Comments
Post a Comment