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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.