i'm a newbie in php, so, i was making a word counter program. I was trying to count how many instances of specific words are in a website. So, i was using Substr_count to count the words, but the issue is that it picks up words like "sunlight" as containing words like "sun".
This is my code.
/*When the user types the word*/
$search = $_POST["texto"];
/*The website*/
$page = $_POST["Web"];
$web = file_get_contents($page);
/*Count words*/
$result = (substr_count(strip_tags(strtolower($web)), strtolower($search)));
/*Display the information*/
if($result == 0){
echo "the word " .mb_strtoupper($search). " doesn't appear";
}else{
echo "the word " .mb_strtoupper($search). " appears $result times";
}
Any way to fix this? I tried str_word_count and preg_match_all but this displays big numbers.