<?php
function dir_array($map, $wt){
	if($bestand = opendir($map)){
		while(false !== ($lees = readdir($bestand))){
			if($lees != "." && $lees != ".."){
				$ex = explode('.', $lees);
				$ext = $ex[count($ex)-1];
				if(is_dir($map."/".$lees)){
					$da = array_merge($da, dir_array($map."/".$lees, $wt));
				}
				elseif(in_array($ext, $wt)){
					$da[] = $map."/".$lees;
				}
			}
		}
		closedir($bestand);		
	}
	return $da;
}
function zoek($array){
	if($array <= 0){
		$sel = '<input type="text" name="bestand" value="'.$_POST["bestand"].'">';
	}
	else{
	echo $map;
		$sel = "	  <select name=\"bestand\">";
		foreach($array as $dir){
			$sel .= "\n	      <option>".$dir."</option>";
		}
		$sel .= "\n	    </select>";
	}
	$form = '<form name="zoek_form" method="post">
  <table width="100%" border="0" cellspacing="0" cellpadding="3">
	<tr>
	  <td><strong>Woord:</strong></td>
	  <td><input type="text" name="woord" value="'.$_POST["woord"].'"></td>
	</tr>
	<tr>
	  <td><strong>Bestand:</strong></td>
	  <td>
'.$sel.'
	  </td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td><input type="submit" name="zoek" value="Zoek"></td>
	</tr>
  </table>
</form>';
	if($_POST["bestand"] != '' && $_POST["woord"] != ''){
		if(file_exists($_POST["bestand"])){
			$bestand = file($_POST["bestand"]);
			$bestand = implode("<br />", $bestand);
			$bestand = preg_replace('/'.$_POST["woord"].'/i', '<font style="background: yellow">'.$_POST["woord"].'</font>', $bestand);
			return $form.'<hr size="1" color="black" />'.$bestand;
		}
		else{
			return $form.'<hr size="1" color="black" />Dit bestand bestaat niet!';
		}
	}
	else{
		return $form;
	}
}
?>