Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 08:41 AM.

  • #2
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •