implementing a website search feature using php

Discussion in 'PHP' started by sudhakararaog, Jul 16, 2008.

  1. #1
    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.
     
    sudhakararaog, Jul 16, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    Sounds fine. Just how many searches do you expect to get though? per day, per hour etc. Using that technique will slow down results and if the # of files gets large it could time out. It would work for a small site with low # of searches, if the site gets bigger will have to move it to an index.
     
    shallowink, Jul 16, 2008 IP
  3. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    I agree with shallowink. Your script will eat the cpu resource if you got thousands searching especially Number 2 and 4. You should store the data into database.
     
    sastro, Jul 16, 2008 IP