www.webdeveloper.com
Results 1 to 3 of 3

Thread: Page through a text file line by line

  1. #1
    Join Date
    Jan 2007
    Posts
    78

    Page through a text file line by line

    I have a text file formatted like;
    PHP Code:
    $data "$username | $realname  | $phone | $email\r\n"
    I will do a search that may return multiple matches.
    How can I display a single line of the text file in a Web form and then click next to go to the next line of the file.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    If the source file is not too huge (for some undefined value of "too huge"), I might just send all the data (perhaps as a JSON object?) and let JavaScript handle the line-by-line display on the browser side.

    If you prefer to do it on the server side, then I'd probably use a typical pagination approach where each request sets an offset counter on the "next" link to indicate how many lines to skip. Then either use fgets() or such in a loop to skip that many lines and then read the new line, or just dump the file into an array with file() and then grab that numbered array element.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jan 2007
    Posts
    78
    Quote Originally Posted by NogDog View Post
    If the source file is not too huge (for some undefined value of "too huge"), I might just send all the data (perhaps as a JSON object?) and let JavaScript handle the line-by-line display on the browser side.

    If you prefer to do it on the server side, then I'd probably use a typical pagination approach where each request sets an offset counter on the "next" link to indicate how many lines to skip. Then either use fgets() or such in a loop to skip that many lines and then read the new line, or just dump the file into an array with file() and then grab that numbered array element.
    NogDog:
    On the server, I can get it to read the first line. Can you provide some sample code to get the other lines 1 @ a time. eg.. a functioning next button .
    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles