Post by NapalM on Mar 4, 2011 17:33:38 GMT
Simple little engine i coded that lists files in a directory then compares the names of the files with search term
I have a demo up here: www.artistwith.in//%21%21_Dylan/scripts/search/index.php?srch=burger
And here's the list of files in the dir on that test site:
amp.txt
burgerking.txt
charo chicken.txt
chicken.txt
fatburger.txt
fried chicken.txt
fries.txt
full throttle.txt
hamburger.txt
in and out burger.txt
luies burger.txt
mc chicken.txt
mcdonalds.txt
monster.txt
papa johns.txt
pizza hut.txt
rockstar.txt
toco bell.txt
wendys.txt
simple enough.....I'll update it more later maybe....I know there are some parts that are pointless like the double filter...But i'm lazy to fix right now.
<?php
//Search engine by Dylan Falk-Hutchings [url]http://artistwith.in[/url]
$dirname = "files_dir"; //Directory to search
echo '<form action="" method="GET"><input type="text" name="srch"><input type="submit" value="search"></form>'; //Search Form
$cletitle = strip_tags($_GET[srch]); //Strips the search item of html tags.
$cleantitle = preg_replace("/^[^a-z0-9]?(.*?)[^a-z0-9]?$/i", "$1", $cletitle); //Strips the search item of anything other than text and numbers.
echo '<h2 style="margin: 0 0 0 0; padding: 0 0 0 0;">'.$cleantitle.'</h2>'; //Just a bold of what you are searching
//Listing of the files, the search results part...
$dir = opendir($dirname);
while(false != ($file = readdir($dir))){
if(($file != ".") and ($file != "..")){
$srch1 = strtolower($file);
$srch2 = strtolower($cleantitle);
$i = similar_text($srch1, $srch2, &$p);
if($p > 35){
$surch = yes; //if nothing is found, then it wont be yes now will it?
echo '<a href="'.$dirname.'/'.$file.'">'.$file.'</a><br />'; //What to show when a search result comes up....
}
}
}
if($surch == yes){}else{
echo 'Were sorry, no results were found.';
}
?>
I have a demo up here: www.artistwith.in//%21%21_Dylan/scripts/search/index.php?srch=burger
And here's the list of files in the dir on that test site:
amp.txt
burgerking.txt
charo chicken.txt
chicken.txt
fatburger.txt
fried chicken.txt
fries.txt
full throttle.txt
hamburger.txt
in and out burger.txt
luies burger.txt
mc chicken.txt
mcdonalds.txt
monster.txt
papa johns.txt
pizza hut.txt
rockstar.txt
toco bell.txt
wendys.txt
simple enough.....I'll update it more later maybe....I know there are some parts that are pointless like the double filter...But i'm lazy to fix right now.