I am trying to build a search system and retrieving matching records. in this case.. i wanna let users use some especial chars for exactly build their requests. so i put these signs and then converting them to a correct SQL:
+ should be converted ro AND
/ should be converted ro OR
“ should be converted ro ( or )
for example when user entered: “book/pen”+paper
it should be converted to SQL WHERE clause:
( (myfield LIKE “%book%”) OR (myfield LIKE “%pen%”) ) AND ( myfield LIKE “%paper%”)
i implemented this with a switch case and arrays.. but i guess that there are another quick way to do that (such as regEx). have you any idea for solving it?
NOTE 1: I should collect all term from this expression and save them in another table. so, i need to collect them in an array.
NOTE 2: terms can be write in all world languages! from English to Arabic,Persian,.. may be Chinese!!!!
Thanks
Have a try with :
output: