Search for full words in mysql with php
The easiest way to search for full words in mysql is to use regular expressions. According to this article you need to use these markers - [[:<:]], [[:>:]] -
that stand for word boundaries.
First, build a variable from the search parameter :
$val = addslashes($_GET[’search’]);
Construct a regular expression pattern:
$reg =’[[:<:]]’. $val .’[[:>:]]’ ;
Finally, build a sql statement:
Select comments from table1 where comments REGEXP ‘$reg’
So far, it has worked for me.
