Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004
    Posts
    1

    Unanswered: Data From Certain Line In txt Files

    ok, i know how to show a certain line from a text file but say I had a text file like this:

    bill | 23 | php
    fred | 19 | cgi
    frank | 20 | asp
    brian | 33 | php
    edward | 27 | php
    james | 30 | asp

    how would go about getting the data of lines 3 to 5? like this:

    frank | 20 | asp
    brian | 33 | php
    edward | 27 | php

    Thanks in advance!

  2. #2
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    10
    I do not realy understand what your problem is, but i think this will help you:

    PHP Code:
    fscanf resource handlestring format [, string var1]) 
    example:
    PHP Code:
    fscanf($stream,"%s | %s | %s",$name,$id,$what); 
    but i do not know if this work ...

    good luck ;P

    //EDIT

    here is a url
    Last edited by princes; 11-09-04 at 11:34. Reason: forgotten URL
    [/.. H๖re alles, glaube wenig, sage nichts ..\]

  3. #3
    Join Date
    Jan 2004
    Posts
    35

    Smile Read into an Array

    You should be able to read information by each line into an array. Remember an array starts with a '0'. Here is some code that I have used in the past to read each rows and then also split them out which may be what you want to do anyway.

    // -- Variables --
    $file_dir = "mydir"; // Directory Of Text File
    $myfile = "myfile.txt"; // Text File
    $filearray= file("$file_dir/$myfile"); // Opens File for Array Reading

    // -- Splitting array per line by delmiter | in file
    // -- Getting line 3 - 5 into array
    // -- You may have to change the '3' at the end of the line to pertain
    // to you depending on how you want to parse it.
    list($row3_left,$row3_middle,$row3_right)= split("|",$filearray[2], 3);
    list($row4_left,$row4_middle,$row4_right)= split("|",$filearray[3], 3);
    list($row5_left,$row5_middle,$row5_right)= split("|",$filearray[4], 3);


    Doing this will create a total of nine parsed out variables you can use.

    I have not tested this with your information, but this should be close to what you need to use it for.

    Hopfully this helps

Posting Permissions

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