Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-30-2011, 07:26 AM   PM User | #1
sbhar
New to the CF scene

 
Join Date: Aug 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
sbhar is an unknown quantity at this point
jquery keyword search in external html files

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

Last edited by sbhar; 08-30-2011 at 07:41 AM..
sbhar is offline   Reply With Quote
Old 08-30-2011, 08:46 AM   PM User | #2
sbhar
New to the CF scene

 
Join Date: Aug 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
sbhar is an unknown quantity at this point
keyword search html files

Code:
<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>

Code:
<?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
sbhar is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:45 AM.


Advertisement
Log in to turn off these ads.