Ok, here's the deal...
I am making a search engine for my site. Right now I have it go through a directory, fread all of the files into an array, then split the array twice to get the information between the <TITLE> and </TITLE> tags. Then I compare it to the keyword and if it matches (or contains) the keyword, It is displayed. But because of the way it's set up, I can't get it to put a certain number of results per pages...
Besides getting that working, I would also like to make it check for only files with .htm or .html or .xml or .php etc. And finally, I'd also like to keep a count of the displayed files that i can put in the text before the relative links... so it would say something like...
"Your search for $srchval produced the following $count results...
Now reading results 1-20 out of 113";
heres the code that I'm using so far, keep in mind that this is my first search in php, and if you can fix the code to work more efficiently, make the tasks that i am trying to accomplish easier, or help in any way... please do... Please forgive any sloppiness in the code, I just started and I'm getting less sloppy every day 🙂..
<?php
//CHECK FOR A KEYWORD////////
if((!isset($srchval)) || ($srchval=="")){
echo "Your search cannot be completed. You must enter a word(s) to search for.";
}
////////////////////////////
else{
//CHECK AND SET $PAGENUM////
if(!isset($pagenum)){
$pagenum=1;
}
///////////////////////////
echo "<strong>Your search for \"$srchval\" produced the following results...</strong><br><br>";
if ($dir = @opendir(".")){
while($file = readdir($dir)){
$fp=fopen($file,"rb");
$content=fread($fp,filesize($file));
fclose($fp);
$firstr=explode("<TITLE>",$content);
$finsrch=explode("</TITLE>",$firstr[1]);
if(stristr($finsrch[0], $srchval)!==false){
echo "<a href=\"index.php?area=$file\">$finsrch[0]</a><br>";
}
}
closedir($dir);
}
}
?>
Thank you in advance 😉