How can I match a word in a sentence from a column using regex? I tried:
"select * from table where column regex '/\b".$text."\b/i'"
but that didn't work. Thanks in advance.
How can I match a word in a sentence from a column using regex? I tried:
"select * from table where column regex '/\b".$text."\b/i'"
but that didn't work. Thanks in advance.
MySQL is particularly bad about stuff like this. I'd recommend using MATCH AGAINST syntax http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html or using something like SOLR if you're going to be doing this in volume.
Try this:
"SELECT * FROM table WHERE column REGEXP '[[:<:]]" . $text . "[[:>:]]'"
You should make sure that any characters that could be interpreted as special characters in $text are properly escaped. You should also ensure that you do not get an SQL injection.
I think you want the LIKE clause!
SELECT * FROM table WHERE column LIKE '%value%'
Also please read UltimateBrent's answer as full text search is a very good point.