search text file

Discussion in 'PHP' started by t7584, Mar 3, 2006.

  1. #1
    in my guestbook entries are stored in a text file
    could anybody give information or links to articles on how to search text file and display results with pagination
     
    t7584, Mar 3, 2006 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Producing a search engine in php is not the easiest thing to do. You would achieve more functionality if you could store the data in a database and use the excellent full text search capabilities of MYSQL.

    If you do want to read the contents of the text file you would need to write a script to use the file_get_contents(); command to store the text file as a string and then check for the existance of the search string using strpos or similar.
     
    mad4, Mar 3, 2006 IP
  3. wwm

    wwm Peon

    Messages:
    308
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    oh boy,
    text files dont scale well, databases do

    anyways if u want to search the textfiles heres pseudo code

    ------------------
    make an array

    have a loop that opens each tect file at a time,
    read the contents of each text file into a string

    add this string into the array


    once u looped thru all the files, search the array for the word u want


    ------------------------------
     
    wwm, Mar 3, 2006 IP
  4. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Certainly if you have multiple text files is complicates things somewhat and you need to loop through them as wwm pointed out.

    I had assumed you had one text file?
     
    mad4, Mar 3, 2006 IP
  5. t7584

    t7584 Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    how to compare strings in php?

    in perl it's like this
    if ($line =~ /pattern/){
    }
    searches $line for a pattern of characters placed within the forward slashes on the right
    how will it look like in php?
     
    t7584, Mar 3, 2006 IP
  6. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #6
    strpos will do this for you, check the link in my other post.
     
    mad4, Mar 3, 2006 IP