PHP Search in folders and subfolders

Search in folders and subfolders

<?
$dir = "web";

set_time_limit("0");

echo "<form method=post action=?>
<input class=form type=textbox name=search>
<input class=button type=Submit name=submit value=Submit>
</form>";

extract($_POST);

if (isset($search) && $search != "" && is_dir($dir)) {
  if (strlen($search) < "3") { echo "Use more than 3 symbols"; }
  else { davai("$dir","$search"); }
}

function davai($dir,$string) {
  $handle = opendir($dir);
  while ($file = readdir($handle)) {
    if ($file != "." && $file != "..") {
      if (is_file("$dir/$file")) {
        if (eregi("$string", "$file")) { echo "<A href='$dir/$file'>$file</A><BR>"; }
      }
      else { davai("$dir/$file",$string); }
    }
  }
}
?>