Jump to content

implementing a website search feature using php


sudhakararaog

Recommended Posts

i want to implement a feature where a user searches with a keyword and search results are displayed according to the keyword

 

or phrase entered by the user.

 

following are the steps i want to follow. please advice if i am missing out any steps or i can add any step.

 

1. read the keyword entered by user using $search = $_POST["searchkeyword"];

 

2. read all the files from the root directory into a variable (as all files will be saved in the root directory)

 

3. from step 2 filter and read only files with html and php extensions into a variable

 

4. read the entire contents of all html and php files into a variable

 

5. compare $search with all the individual html and php file contents from step 4

 

6. if a match is found with either html or php file then display a brief title and brief description which will be a link to

 

the actual file which has the keyword.

 

7. display search results in a serial order as 1. Brief Title of the page 2. Brief Title of the page ...

 

8. at the bottom of the page based on the total number of results found from step 6 i would like to provide a link to page 1

page 2 page3 ... (i can decide to display only 10 results per page)

 

please advice.

 

any help will be greatly appreciated.

 

thanks.

 

I can point you in the right direction

 

opendir() - to open root

readdir() - get all the filenames

explode() - break the file names apart so you can get the extension

count() - count the amount of times the file was broken and get the last element to get the extension

fopen() - open a file for reading that matches your requirements

fread() - read the file

eregi() - to match the words

 

Unless you want the experience or the satisfaction that you made this, why remake the wheel.  There are a million search scripts out there that can be modified open source.  I use sphider from sourceforge and it does a nice job.  There is even an updated version of sphider as well.

 

http://www.sphider.eu/

Now, I will say this.  The zip file from their website was corrupted and would not allow me to pull their files out. I had repair their zip file with WinRar to pull their files out.  Once I got the files, everything was fantastic however.

 

Check out the website: Spectacular Computer Repair

 

Go to the website and search for computer.

 

Wayne

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.