This question already has an answer here:
I need a script that will return a count of how many times a specified word appears on webpage. Does anyone know how to do this with PHP? The code will be like this:
<?php
$url="watever.com";
the script here
echo(result);
?>
I do have this little bit that just gives a count of how many times every word on the webpage appears but I am not quite sure how to modify it for just one word.
$str = file_get_contents('http://www.example.com/');
print_r(array_count_values(str_word_count(strip_tags(strtolower($str)), 1)));
</div>
Try using substr_count:
$result = (substr_count(strip_tags($str),"mycoolword"));
I think you're looking for substr_count.
substr_count - Count the number of substring occurrences
Look into using preg_match - http://php.net/manual/en/function.preg-match.php
One of the parameters is $matches, which if passed will put all the matches in that array, so you could get the count by doing a count($matches).
The php page has good examples, here is one:
<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>