-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
87 lines (59 loc) · 1.24 KB
/
app.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
$file = fopen("http://terriblytinytales.com/test.txt","r");
$map = array();
while(!feof($file))
{
$text = fgets($file);
$subtext ="";
$text = strtolower($text);
for($i=0;$i<strlen($text);$i++){
if($text[$i]==' '){
if(strlen($subtext)>0){
if(array_key_exists($subtext,$map)){
$map[$subtext]++;}
else{
$map[$subtext]=1; }
}
$subtext="";
}
else{
$subtext=$subtext.$text[$i];
}
}
if(strlen($subtext)>0){
if(array_key_exists($subtext,$map)){
$map[$subtext]++;}
else{
$map[$subtext]=1;
}
}
}
fclose($file);
arsort($map);
?>
<!DOCTYPE html>
<html>
<body>
<TABLE BORDER="5" WIDTH="50%" CELLPADDING="4" CELLSPACING="3">
<TR>
<TH COLSPAN="2"><BR><H3>TOP WORDS</H3>
</TH>
</TR>
<TR>
<TH>Words</TH>
<TH>Count</TH>
</TR>
<?php
$i=0;
$n=$_POST['val'];
foreach($map as $key => $row) {
if($i>=$n)
break;
if (ctype_alpha($key)){ $i++;
echo "<tr>";
echo "<TD>" . $key . "</TD>";
echo "<td>" . $row . "</td>";
echo "</tr>";} } ?>
</TABLE>
</body>
</html>