PHP/String/String Count

Материал из Web эксперт
Перейти к: навигация, поиск

String word count

<?php
$summary = <<< summary
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text  
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
summary;
   $words = str_word_count($summary);
   echo "Total words in summary: $words";
?>



String word count and frequency

<?php
$summary = <<< summary
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text  
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
summary;
   $words = str_word_count($summary,2);
   $frequency = array_count_values($words);
   print_r($frequency);
?>