yanjchan Posted July 30, 2009 Share Posted July 30, 2009 Hello! Yes, I know on the index page it shows how to make a simple mysql search engine. However, I would like to make this search engine without using mysql if possible, so that I don't have to manage a database. I've been trying to modify a piece of code for hours. This is, basically, the original file. <?php if ($_GET['name'] != '') { $files = glob('maps/*.*'); $results = array(); $query = explode(' ', $_GET['name']); foreach ($files as $file) { $x = 0; if (stripos(basename($file), $query[0]) !== false) { $results[] = $file; } } if (count($results) > 0) { echo count($results).' files matched the search <em>' . htmlentities($_GET['name']) . "</em>:<br /><br />\n"; foreach ($results as $file) { echo '<a href="' . $file . '">' . basename(substr_replace($file ,"",-) . '</a><br />' . "\n"; } } else { echo 'No files matched the search <em>' . htmlentities($_GET['name']) . "</em>.<br />\n"; } } else { echo 'Search the files:<br />'; } ?> <br /> <form action="index.php" method="get"> <input type="text" name="name" /> <input type="submit" /> </form> <?php $files = glob('maps/*.*'); echo "Searching through ".count($files)." files, with more added daily.<br>"; ?> Anyways, the problem is that if you enter multiple words, (for example, example file,) and the name of the file is something like example blah file, it wont recognize it. Ive tried exploding the query into the component words... But I'm stuck there. So now I'm asking the experts to help. Please help me! Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/168089-php-search-engine-files-in-a-directory/ Share on other sites More sharing options...
yanjchan Posted July 30, 2009 Author Share Posted July 30, 2009 Bump? Quote Link to comment https://forums.phpfreaks.com/topic/168089-php-search-engine-files-in-a-directory/#findComment-887050 Share on other sites More sharing options...
mikesta707 Posted July 30, 2009 Share Posted July 30, 2009 well first off the following line stripos(basename($file), $query[0]) !== false only checks if the first word of the query is in the file name something like foreach ($query as $q){ if (stripos(basename($file), $q]) !== false){ $results[] = $file; break; } } instead of that if statement will check every word of the query also I think you may want to use the array_push function instead of the line $results[] = $file; It's been a bit of time since I've tangoed with PhP heavily, but I am not sure if you can add entries into an array that way hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/168089-php-search-engine-files-in-a-directory/#findComment-887054 Share on other sites More sharing options...
yanjchan Posted July 30, 2009 Author Share Posted July 30, 2009 $results[] = $file works. Thank you for your example code, I'll try to apply it. I was confused on how to structure it. Quote Link to comment https://forums.phpfreaks.com/topic/168089-php-search-engine-files-in-a-directory/#findComment-887056 Share on other sites More sharing options...
mikesta707 Posted July 30, 2009 Share Posted July 30, 2009 ok just wasn't sure, been doing java lately, Quote Link to comment https://forums.phpfreaks.com/topic/168089-php-search-engine-files-in-a-directory/#findComment-887061 Share on other sites More sharing options...
yanjchan Posted July 31, 2009 Author Share Posted July 31, 2009 Hmm, I'm still not exactly sure. Using that creates duplicates entries, it would seem. Quote Link to comment https://forums.phpfreaks.com/topic/168089-php-search-engine-files-in-a-directory/#findComment-888015 Share on other sites More sharing options...
yanjchan Posted August 1, 2009 Author Share Posted August 1, 2009 B-bump. Quote Link to comment https://forums.phpfreaks.com/topic/168089-php-search-engine-files-in-a-directory/#findComment-888051 Share on other sites More sharing options...
yanjchan Posted August 1, 2009 Author Share Posted August 1, 2009 I've tried more things, but still can't get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/168089-php-search-engine-files-in-a-directory/#findComment-888088 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.