View Full Version : How many matches of x word in message?
08-10-2007, 11:07 PM
Hello, I have tried learning preg_match & preg_match_all, but its no use, can anyone make me a small piece of code that would count how many times x word was found in x message? Please, or at least explain me how to do one.
08-10-2007, 11:51 PM
How about this:
$haystack="does php rock or does phprock";//deliberate mising space.
print "found:".preg_match_all($pattern, $haystack, $matches)."\n"; //prints found:1 since it doesn't count phprock.
Or you could always use substr_count (http://uk2.php.net/manual/en/function.substr-count.php);)
08-10-2007, 11:58 PM
I had no idea that function was there.... Thanks a lot anyways!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.