The substr_count() function returns the number of times one string occurs within another. Its prototype follows:
int substr_count(string str, string substring)
The following example determines the number of times an IT consultant uses various buzzwords in his presentation:
<?php
$buzzwords = array("mindshare", "synergy", "space");
$talk = "I'm certain that we could dominate mindshare in this space with
our new product, establishing a true synergy between the marketing
and product development teams. We'll own this space in three months.";
foreach($buzzwords as $bw) {
echo "The word $bw appears ".substr_count($talk,$bw)." time(s).<br />";
}
?>
This returns the following:
——————————————–
The word mindshare appears 1 time(s).
The word synergy appears 1 time(s).
The word space appears 2 time(s).
——————————————–
