Results 1 to 2 of 2

Thread: search function on flat file

  1. #1
    Join Date
    Dec 2010
    Thanked 0 Times in 0 Posts

    Default search function on flat file

    I have a text file database and here are the sample contents:

    server1|title1|image url1|category1|video id1
    server2|title2|image url2|category2|video id2
    server3|title3|image url3|category3|video id3
    server4|title4|image url4|category4|video id4
    server5|title5|image url5|category5|video id5

    How to make a search feature that will generate a result like the one below if someone will write any part of the TITLE on the search box?

    <a href="video.php?v=server1&id=video id1&t=title1">title1</a>

    Please help me on this... I'm surfing on the net for 12 hrs but can't find anything close to the function I want.
    I am making a simple script out of php codes I collected on the net. I dont know anything about codes, I only know how to analyze it and make some trial and error...
    Thank you in advance!

  2. #2
    Join Date
    Apr 2008
    Thanked 516 Times in 502 Posts
    Blog Entries


    two approaches:

    1) read the file into an array, and simply search the array for your keyword.

    2) read the file one line at a time and use a regex to look for matches.

    either way is going to be highly inefficient, especially if you have a lot of entries. a database is much better suited to this sort of task.

    if you decide to you flat files, I'd recommend storing your records in JSON format - much quicker and easier to translate into PHP. You also might separate each "column" into its own text file (so when you search a specific column, you only have to load the data for THAT column).


Posting Permissions

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