<h3>Compter les mots</h3>
<form method="post">
<input type="text" name="site" value="http://" size="50" 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=navcl
ient&hl=fr&q=$word\">";
echo $word."</a></td><td>($cnt)</td></tr>";
}
}
echo "</table>";
}
?>
|