Page 1 of 1
Putting together a glob search with wildcards
Posted: Thu May 04, 2006 12:19 pm
by ozzy
I've got the basis of it right, but i just dont know how to make it all work together. What im wanting to do is create a search using glob() to search a directory
I was thinking something like:
Code: Select all
$term = trim($_POST['search']);
$files = glob($dir."/files/*".$term."*");
And the '*' will work as the wildcard. So that's all working fine, but what do i do next. Someone suggested that i use "a loop, or use print_r()", but how do i do that? Something like:
Code: Select all
function printr ( $files , $term = '' ) {
Prob not, but that's all i could of. Any help? thanks in advance!

Posted: Thu May 04, 2006 12:59 pm
by Oren
Posted: Thu May 04, 2006 3:12 pm
by ozzy
Ah, cool. This is my script, but it doesnt seem to work, any suggestions?
Code: Select all
<form action="" method="POST"><input size="25" type="text" name="query" value=""> <input type="submit" value="Search"></form>
<?php
$term = trim($_POST['search']);
$files = glob($dir."files/*".$term."*");
print_r($files);
?>
Posted: Thu May 04, 2006 3:32 pm
by feyd
maybe $_POST['query']?
Posted: Thu May 04, 2006 3:35 pm
by ozzy
still doesnt seem to change anything.
Posted: Thu May 04, 2006 3:39 pm
by feyd
What's the new code and what are you using as input?
Posted: Thu May 04, 2006 3:43 pm
by ozzy
This:
Code: Select all
<form action="search.php" method="POST"><input size="25" type="text" name="query" value=""> <input type="submit" value="Search"></form>
<?php
$files = glob($dir."files/*".$term."*");
$term = trim($_POST['query']);
print_r($files);
?>
Posted: Thu May 04, 2006 3:53 pm
by feyd
$term is set after it's been used in
glob()?
Posted: Thu May 04, 2006 4:20 pm
by ozzy
Ooops..
i still get the problem when i move it...
Code: Select all
<form action="search.php" method="POST"><input size="25" type="text" name="query" value=""> <input type="submit" value="Search"></form>
<?php
$term = trim($_POST['query']);
$files = glob($dir."files/*".$term."*");
print_r($files);
?>
Posted: Thu May 04, 2006 4:24 pm
by feyd
Have you verified what is being sent to glob()? I have yet to understand what "problem" you're actually having. Maybe you need to adjust what you are sending to glob?