forked from glugnith/glug.nith.ac.in
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glug_search.php
51 lines (45 loc) · 1.02 KB
/
glug_search.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
<?php
set_time_limit("600");
$keyword=trim($_POST["glug_search"]);
if($keyword==""){
echo"Please enter your keyword";
exit;
}
function listFiles($dir,$keyword,&$array){
$handle=opendir($dir);
while(($file=readdir($handle))!==false){
if($file!="."&&$file!=".."){ //if it is a directory, then continue
if(is_dir("$dir/$file")){
listFiles("$dir/$file",$keyword,$array);
}
else{
$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file")); //read file
if(stristr("<body([^>]+)>(.+)</body>",$data,$b)){
$body=strip_tags($b["2"]);
}
else{
$body=strip_tags($data);
}
if($file!="glug_search.php"){
if(stristr("$keyword",$body)){
if(stristr("<title>(.+)</title>",$data,$m)){
$title=$m["1"];
}
else{
$title="no title";
}
$array[]="$dir/$file $title";
}
}
}
}
}
}
$array=array();
listFiles(".","$keyword",$array);
foreach($array as $value){
list($filedir,$title)=split("[ ]",$value,"2");
echo "$title "."
\n";
}
?>