Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    137
    Thanks
    1
    Thanked 0 Times in 0 Posts

    implementing a website search feature using php

    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.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,377
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    Searches are best done with databases, but in your case, you want to search
    many pages. It can be done, but depending on how many pages, you might end
    up with some PHP timeouts. The PHP script needs to open each file and search for
    the keyword. A lot of pages will be a lot of processing time.

    1)
    Reading the directory method depends on your PHP version ... 4 or 5?
    The list is stored in an array.

    2)
    You go through the array and open each file.
    Search for keyword
    If found, grab between <title> and </title>
    and grab description, parse out the description meta tag
    Display as found.

    Parsing is the hardest part ... if you had the ability to add a unique comment
    tag to every page (with a description) that would make it easier ...

    <!--
    <comment>
    This is the description section, or whatever
    would appear in the search results
    </comment>
    -->


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •