Created
November 12, 2012 10:22
-
-
Save PaulFr/4058520 to your computer and use it in GitHub Desktop.
statistiques d'un texte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$text = file_get_contents('ok.txt'); | |
$words = explode(' ', $text); | |
$top = 50; | |
echo 'Il y a '.count($words)." mots\n"; | |
echo 'Il y a '.count(array_unique($words))." mots uniques\n"; | |
echo 'Il y a '.(strlen($text)).' caractères (en comptant les espaces)'."\n"; | |
echo 'Il y a '.(strlen(str_replace(' ', '',$text))).' caractères (sans compter les espaces)'."\n"; | |
$count = array(); | |
foreach($words as $word){ | |
if(!isset($count[$word])) $count[$word] = 0; | |
$count[$word]++; | |
} | |
arsort($count); | |
$i = 0; | |
if($top < count($count)) $top = count($count); | |
foreach($count as $word => $nb){ | |
if(++$i > $top) break; | |
echo $i.'. '.utf8_encode($word).' -> '.$nb."\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment