I want to create advance query builder using PHP code.
Input :
search_String_1 AND( search_String_2 OR search_String_3)
... so on
Goal :
check AND / OR operator rules including () parenthesis and convert it into following String: Query :
db.table.search_field LIKE '
search_String_1' AND ( db.table.search_field LIKE 'search_String_2' OR db.table.search_field LIKE 'search_String_3')'
My efforts:
I have use preg_match()
but I dont know how to check all operator and query sequences by best solution. Also I have exploded user input by "blank_space
" , so i have all token in one array. I am still trying to find solution. If I am wrong or there is a good solution please suggest me to do so.
Thanks for your help.