01 <html>
02 <body>
03 <?php
04     $BasePath = "./";
05     $KeywordDataPath = "keyword.dat";
06 
07     if(!$KeywordDataHandle = fopen($BasePath . $KeywordDataPath, "r")) {
08         die("fopen(ERROR): $BasePath$KeywordDataPath");
09     }
10 
11     $cnt = 0;
12     while ($line = fgets($KeywordDataHandle)) {
13         $word = preg_split("/[\t\n]/", $line);
14         $LineArray[$cnt]['word'] = $word[3];
15         $LineArray[$cnt]['count'] = $word[1];
16         $cnt++;
17     }
18     $LineNum = $cnt;
19 
20     fclose($KeywordDataHandle);
21 
22     printf("<div>found %d lines.</div>\n", $LineNum);
23 
24     mb_internal_encoding("SJIS");
25 
26     $KeywordNum = 0;
27     for($cnt = 0; $cnt < $LineNum; $cnt++) {
28         $words = $LineArray[$cnt]['word'];
29         $words = mb_convert_kana($words, "asK");
30         $words = mb_strtoupper($words);
31         $word = mb_split(' ', $words);
32 
33         foreach($word as $keyword) {
34             if($keyword) {
35                 $KeywordArray[$keyword] += $LineArray[$cnt]['count'];
36                 $KeywordNum++;
37             }
38         }
39     }
40 
41     printf("<div>found %d keywords.</div>\n", $KeywordNum);
42 
43     arsort($KeywordArray);
44 
45     print("    <table>\n");
46 
47     $cnt = 0;
48     foreach($KeywordArray as $key => $val) {
49         if($cnt % 2) {
50             $bgcolor = "#f8f8f8";
51         } else {
52             $bgcolor = "#f0f0f0";
53         }
54 
55         printf("        <tr style=\"background-color: $bgcolor;\"><td align=\"right\">%d</td><td>%s</td><td align=\"right\">%d</td></tr>\n", ($cnt + 1), $key, $val);
56         $cnt++;
57 
58         if(($cnt + 1) > 100) { break; }
59     }
60 
61     print("    </table>\n");
62 ?>
63 </body>
64 </html>