Buyur Hocam:
$text = 'Bu bir deneme testidir. testler çok önemlidir. test yapılmazsa sorun olabilir.';
wordStats($text,"test");
function wordStats($text, $word){
$totalWord = wordCount($text);
$totalSpecificWordInText = substr_count($text, $word);
$percent = round(100*$totalSpecificWordInText/$totalWord);
echo "Bu yazıda toplam ".$totalWord." adet kelime bulunmaktadır.<br>";
echo "Aradığınız kelime bu yazı içerisinde ".$totalSpecificWordInText." adet bulunmaktadır.<br>";
echo "Yüzde oranı : %".$percent;
}
function wordCount($text) {
$text = str_replace(str_split('|'), '', $text);
$text = trim(preg_replace('/s+/', ' ', $text));
$text = preg_replace('/-{2,}/', '', $text);
$len = strlen($text);
if (0 === $len) {
return 0;
}
$words = 1;
while ($len--) {
if (' ' === $text[$len]) {
++$words;
}Sonuç:
Bu yazıda toplam 11 adet kelime bulunmaktadır.
Aradığınız kelime bu yazı içerisinde 3 adet bulunmaktadır.
Yüzde oranı : %27