-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcross.php
More file actions
89 lines (78 loc) · 1.79 KB
/
cross.php
File metadata and controls
89 lines (78 loc) · 1.79 KB
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
86
87
88
89
<html>
<head>
<title></title>
<body>
<style type=”text/css”>
h3:target {
color: white;
background: #f60;
}
</style>
<script>
var oldid = null;
var oldcolor = null;
function highlightLine(id) {
if (oldid != null){
document.getElementById(oldid).style.color = oldcolor;
}
oldcolor= document.getElementById(id).style.color;
oldid = id;
document.getElementById(id).style.color = 'red';
}
</script>
<?php
/*see:
http://www.w3schools.com/php/php_file_upload.asp
for details on file upload using php.
*/
$target_dir = "uploads/";
$target_file = $target_dir. basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 0;
if(isset($_POST["submit"]))
{
$uploadOk = 1;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
}
$lineno=1;
echo "<pre>";
$cross = array();
$data = array();
$file = fopen($target_file,"rb");
while (($line = fgets($file))!= NULL){
$data[$lineno] = $line;
$theWords =str_word_count($line, 1);
for ($i=0;$i<count($theWords);$i++){
$word = $theWords[$i];
if (!isset($cross[$word])){
$cross[$word] = array();
}
array_push($cross[$word],$lineno);
}
$lineno++;
}
/* Output the cross reference Table */
$len = count($cross);
foreach ($cross as $key => $val){
echo $key.' ';
$len1 = count($val);
for ($j=0;$j<$len1;$j++){
echo '<a href="#'.$val[$j].'" onclick='.'"highlightLine(';
echo "'".$val[$j]."')".'"> ';
echo $val[$j].'</a> ';
}
echo "<br>";
}
$len = count($data);
for ($i=1;$i<$len;$i++){
/* output an anchor */
echo '<a name="'.$i.'" id='.'"'.$i.'">'.$data[$i].'</a>';
}
echo "</pre>";
?>
</body>
</html>