php - How can I return records with a MySQL query using a regular expression? -
I have a record in my database that is searched with user input, and initially, to get the correct record Was enough. / P>
"Choose from plants where the '%' like flower. $ SanitizedUserInput"% '" It was all doing well and working well But then things started, the search 'red' was planting with 'red' letters in the order of their 'code'> flower area, and not just the entire word 'red'.
I was just suggested to place any location in the user's input, but I know that this will fail where the word is the area The first word, or the last, I thought of myself, should use regular expression! To find the word where it has a word boundary.
Unfortunately, I have ever used regexs in the database How do you create a query to search a DB with a regex? Hopefully, it is as easy as:
"Choose from plug-ins ID where flower Reggae '/ \ b ". $ SanitizedUserInput" \ B / `"
Yes, this is very easy.
< P> MySQL regular expression has the word border sequence [[: and [[: & gt ;:]] so you end up like something Going:
$ query = "SELECT id" "From Plants" "WHERE Flower Reggae" [[: & lt ;:]] "$ sanitizedUserInput "[[& Gt;:]] '';
Comments
Post a Comment