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