Forum Moderators: coopster

Message Too Old, No Replies

php reading file.

lines form 10 to 13

         

rokec

4:02 pm on Oct 17, 2006 (gmt 0)

10+ Year Member



How can i read lines from 10 to 13 in txt file (texts/text.txt)?

jatar_k

4:18 pm on Oct 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try this thread for some ideas
displaying the last 20 lines from a logfile [webmasterworld.com]

smells so good

4:21 pm on Oct 17, 2006 (gmt 0)

10+ Year Member



I would read the entire file into an array, then set a counter for the lines that you want as you process that array. The following code should give you a jump start. This code assumes that each line is terminated with a newline (\n).

$fstring = fread($fd, filesize('/path/to/file/filename.txt'));
$line = explode ("\n", $fstring);

$linecount = 1;
while (list($key, $val) = each($line)) {
if ($linecount == '10') {
//Do something here
}
}

rokec

5:17 pm on Oct 17, 2006 (gmt 0)

10+ Year Member



I thik that your code is not complete? What is stored in $fd?

smells so good

7:34 pm on Oct 17, 2006 (gmt 0)

10+ Year Member



The resource handle is stored in $fd.

Description
string fread ( resource handle, int length )

My usage was similar to this line
$fd = fopen ('/path/to/file/filename.txt', "r+");

Also incomplete... I am not incrementing the counter in my example.