Page 1 of 1

array of locations

Posted: Wed Jul 07, 2004 2:01 pm
by bimo
I'm writing a search engine that searches a the folder for files that meet the given criteria. Yesterday afternoon I wrote a very basic script that can find the files if the exact criteteria are met but I want it to be able to return multiple files if every form field is not filled in.

The files that are being searched use a pretty good naming system - $program$day$month$year - so I made a form with select elements that correspond to each part of the file name.

Code: Select all

<?php
<!--this is an example of the form values that are sent-->
<select name="dia">
<option value="defaulta">- dia -</option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>... </select>

// here's the php that the GET[] is sent to
if ($_GET) {
	$busqueda = "$programa$dia$mes$ano";
	$filename = "$busqueda.mp3";
	
	if (file_exists($filename)) {
	   print("<a href='$busqueda'>$archivo_nombre</a>");
	} else {
	   print("No encuentra ningun archivo con los criterios dados.  Por favor trata otra vez estando menos especifico.");
	}
}
?>
What I've been thinking is that I need to use regex in cases where the user doesn't make a selection for one of the form elements. For instance if the day (dia) field were left blank, $dia would contain some kind of regular expression so that any day would be fine as long as the other criteria (program month year) were met.


The second question I have is, if there is more than one match, would I need to put them in an array or is there a function that does that like preg(). I think preg() does something like that but I'm not sure if it finds and takes every result until it hits the regex's designated end characters, placing each in the array.

I'm still pretty new to php so please forgive my ignorance.

Thanks, Holly

?>