Jump to content

searching website for keywords


kellz

Recommended Posts

hey all

 

Soo i spent ages thinking of a way i can make a site search function without using SQL and i did it yayness to me! ^_^ here it is:

 

<?php

$search = "search term";
$x=0;
foreach (glob('*.html') as $file) {
    $data = file($file);
$currentfile = $file;

    foreach ($data as $line) {
   if (stristr($line, $search)) {
           if ($x != 1) print "Your keyword '$search' has been located. A section of the text containing that keyword and the URL to that page are listed below."."<br /><br />\n";$x=1;
	   
	   preg_match_all ("/(" . $search . ")/is", $line, $array);
           for ($i=0; $i < sizeof ($array[0]); $i++) {
			$line = str_replace($array[0][$i], '<i style="color:#339900;">' . $array[0][$i] . "</i>", $line);
           }
           echo "URL: $currentfile <br />Preview: <br />". $line . "<br /><hr />\n";
   }
    }

}


?>

 

I guess readers already understand the code? lol anyway yesh i am kinda crappy and I know it could do with a face lift so what else could i do? is there something i "should" be using instead of something i am using?

 

ps: Happy halloween! wooo i got candy! and money (ofcourse) never to old for it!

 

Link to comment
https://forums.phpfreaks.com/topic/75591-searching-website-for-keywords/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.