Reputation: 4564
this is what I have right now:
$text = "test";
$count = substr_count($text, "Hello Everyone this is a
test test test that im testing");
the value $count is 4. I would like to say 3 instead because the word testing is not the same as test. I am open to doing this using regular expressions if its better/easier ? any suggestions please
Upvotes: 1
Views: 1063
Reputation: 173562
Use the word boundary escape sequence \b
in preg_match_all()
:
$count = preg_match_all('/\btest\b/', "Hello Everyone this is a
test test test that im testing");
See also: Escape sequences
Upvotes: 2