Created
April 10, 2012 18:56
-
-
Save legierski/2353673 to your computer and use it in GitHub Desktop.
Shows 20 most popular words in a text file
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
<? | |
$book = file_get_contents('book.txt'); | |
$book = strtolower($book); | |
$book = str_replace(array('.', ',', ':', ';', '"', "'", '?', '!', '-', '`'), '', $book); | |
$words = explode(' ', $book); | |
$stats = array_count_values($words); | |
arsort($stats); | |
echo count($words).' words in book<br><br>'; | |
echo '20 most popular words:<br><br>'; | |
$i = 0; | |
foreach($stats as $word => $counter) { | |
echo ++$i.' <a href="http://translate.google.com/#es|en|'.$word.'">'.$word.'</a> ('.$counter.' times)<br>'; | |
if($i >= 20) { | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment