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 ? Link to comment https://forums.phpfreaks.com/topic/258041-search-for-keyword-in-sentence/ 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 } Link to comment https://forums.phpfreaks.com/topic/258041-search-for-keyword-in-sentence/#findComment-1322719 Share on other sites More sharing options...
ankur0101 Posted March 1, 2012 Author Share Posted March 1, 2012 Thanks Problem solved :-) Link to comment https://forums.phpfreaks.com/topic/258041-search-for-keyword-in-sentence/#findComment-1322730 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.