<?
 //  A keyword search routine for your .html and .php files

 function check($word,$dir,$word){
    if(is_readable($dir)){
       $d = opendir($dir);
       if($d){
          while($f = readdir($d))
          {
              if($f != "." && $f != ".." && is_readable("$dir/$f")){

                if(is_dir("$dir/$f"))
                     check($word,"$dir/$f",$word);
                else if(preg_match("/.html$/i","$dir/$f") || preg_match("/.php$/i","$dir/$f"))
        {
              $ar = file("$dir/$f");
                      while(list($index,$line)=each($ar)){
                          $expr = preg_quote("$word");
                          if(preg_match("/$expr/i",$line)){
                                # Remove beginning of file path
                                # /web/crit/
                                # 12345678910
                $relDir = substr($dir,10); 
                                  print("<a href=/crit/$relDir/$f>$f</a><br>");
                break;
              }
              }

        }
              }
          }
          closedir($d);
       }
    }
 }

 if(empty($q)){
    print("Search term? <form action=$PHP_SELF><input name=q></form>");
 }else{
        print("<h1>Results for search term $q</h1>");
        check($word,"/web/crit",$q);
 }
?>