I have been trying to match my one variable with the other. All I want that variable let’s say $word contains no matter what in it matches with the the other variable lets say $search_in and echo results accordingly.
I have been using if (preg_match("/$word/i", $search_in)) echo "matches"; but I am getting a lot of warnings like the following as I applied regexp on the values being returned from DB.
Warning: preg_match() [function.preg-match]: Unknown modifier ‘(‘
Warning: preg_match() [function.preg-match]: Unknown modifier ‘T’
$wordmost likely contains a slash in it.You should use
striposfor this, since you don’t need the power of regular expressions at all:For the record, the
preg_matchway of doing it would be:Always prefer the string functions to regular expressions when the former can do the job.