<?php
function count_word_frequency($str,$word){
$words = preg_split('/([\s\-_,:;?!\/\(\)\[\]{}<>\r\n"]|(?<!\d)\.(?!\d))/',$str);
$count = 0;
foreach($words as $key=>$value){
if($value == $word){
$count++;
}
}
return $count;
}
?>
As we can seen that the function above use two parameters. That are $str (containt sentence) and $word (word which would be counted frequency in the $str). So, if you wanna try that function, you just call that function by type count_word_frequency(“YOUR_SENTENCE”, “YOUR_WORD”) in your code. Thank you!
No comments:
Post a Comment