ankur0101 Posted March 1, 2012 Share Posted March 1, 2012 Hi, I want to search for keywords in a sentence Something like >> $abc = "I drink water. I drink vodka too."; if (word 'water' found in $abc or word 'vodka' found in $abc) { echo "I found some kind of liquid"; } How can I do that ? Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted March 1, 2012 Share Posted March 1, 2012 $abc = "I drink water. I drink vodka too."; $regex = '~\b(water|vodka)\b~i'; if(preg_match($regex, $abc)) { // Found a match } Quote Link to comment Share on other sites More sharing options...
ankur0101 Posted March 1, 2012 Author Share Posted March 1, 2012 Thanks Problem solved :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.