...

View Full Version : jquery keyword search in external html files



sbhar
08-30-2011, 07:26 AM
Hi

I need to develop a simple keyword search in external html files(having traversing in directories ability).

Is this possible?
(in this case php can be used)

Please guide me

Thanks

sbhar
08-30-2011, 08:46 AM
<html>
<head>
<title>Web Search </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="search.php">
<table cellspacing="0" cellpadding="5" bgcolor="#EEEEEE" align="center">
<tr>
<td>
<div align="center">
<input type="text" name="keyword">
</div>
</td>
<td>
<input type="submit" name="Submit" value="Search">
</td>
</tr>
</table>
</form>
</body>
</html>






<?php
set_time_limit("600");
$keyword=trim($_POST["keyword"]);
if($keyword==""){
echo"Please enter your keyword";
exit;
}
function listFiles($dir,$keyword,&$array){
$handle=opendir($dir);
while(false!==($file=readdir($handle))){
if($file!="."&&$file!=".."){
if(is_dir("$dir/$file")){
listFiles("$dir/$file",$keyword,$array);
}
else{
if(eregi("([.]html)|([.]htm)|([.]php)", $file)){
$data=file_get_contents("$dir/$file");
if(eregi("<body([^>]+)>(.+)</body>",$data,$b)){
$body=strip_tags($b["2"]);
}
else{
$body=strip_tags($data);
}
if($file!="search.php"){
if(eregi("$keyword",$body)){
if(eregi("<title>(.+)</title>",$data,$m)){
$title=$m["1"];
}
else{
$title="No Title";
}
$array[]="$dir/$file $title";
}
}
}
}
}
}
}
$array=array();
listFiles(".","$keyword",$array);
$resultnum=count($array);
echo "<table width=60% bgcolor=#eeeeee align=center cellpadding=20><tr><td>";
echo "<B>Find ".$resultnum." results</B>";
echo " <a href=search.html>New Search</a><br><br>";
foreach($array as $value){
list($filedir,$title)=split("[ ]",$value,"2");
echo "<a href=$filedir target=_blank>$title </a>"."<br>\n";
}
echo "</td></tr></table>";
?>



This is a solution I got by searching net using Google.

Please help me

1. to get the results without page refresh
2. replace eregi with preg_match



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum