1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
le code est à mettre dans un fichier compte.php dans votre site:
<h3>Compter les mots</h3> <form method="post"> <input type="text" name="site" value="http://" size="100" maxlength="255"> <input type="submit" value="Submit"> </form> <?php
if ($site) { $fp = fopen($site, "r"); $file = str_replace(" ", " ", strip_tags(fread($fp, 100000))); $file = str_replace("\"", " ", $file); $file = ereg_replace("[0-9]"," ", $file); fclose($fp);
//compte les mots $words_to_count = strip_tags($file); $pattern = "/[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-\-|:|\&|@)]+/"; $words_to_count = preg_replace ($pattern, " ", $words_to_count); $words_to_count = trim($words_to_count); $total_words = count(explode(" ",$words_to_count));
echo "Il y a $total_words mots dans <a href=\"$site\" target=\"_blank\">$site</ a>."; echo "<br>Les plus communs sont:";
$string = $words_to_count;
$arr = spliti("[^a-z0-9]+",$string);
$idx = array(); foreach($arr as $word) { trim($word); if(strlen($word)<1) continue; $word = strtolower($word); $idx[$word]++; }
echo "<table>"; arsort ($idx); foreach($idx as $word=>$cnt) { if ($cnt >3 and strlen($word)>3){ echo "<tr><td><a href=\"http://www.google.fr/search?sourceid=navclient&hl=fr &q=$word\">"; echo $word."</a></td><td>($cnt)</td></tr>"; } } echo "</table>"; } ?> |