Re: [PHP] Printing line x in a file
On Sun, 2002-05-12 at 00:10, Miguel Cruz wrote: On Sat, 11 May 2002, Andrew Conner wrote: I have a script where I need to get the text from line number $line in file $filename then save it to a var ($text) and then print it. For example, in the file lamb.txt (just an example file): Mary was a little lamb, whose fleece was as white as snow. I need to get line number 3 (fleece) and print it (print $text). How would I go about this? Perhaps you might say, using a for loop, with x=$somelineno, type of format might be the easiest way to do this from user input or some such thing. fopen() the file and call fgets() three times. The return from the third fgets call will contain the third line (including the terminating newline, so strip() it if you don't want that). miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Austin Gonyou Systems Architect, CCNA Coremetrics, Inc. Phone: 512-698-7250 email: [EMAIL PROTECTED] One ought never to turn one's back on a threatened danger and try to run away from it. If you do that, you will double the danger. But if you meet it promptly and without flinching, you will reduce the danger by half. Sir Winston Churchill signature.asc Description: This is a digitally signed message part
Re: [PHP] Printing line x in a file
If the file is relatively small, then the easiest would be to use file() which reads a file into an array $file_array=file($filename); $text=$file_array[$line]; cheers, thalis On Sat, 11 May 2002, Andrew Conner wrote: I have a script where I need to get the text from line number $line in file $filename then save it to a var ($text) and then print it. For example, in the file lamb.txt (just an example file): Mary was a little lamb, whose fleece was as white as snow. I need to get line number 3 (fleece) and print it (print $text). How would I go about this? Andrew Conner (All apologies if this messes up and does a multi-post) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Printing line x in a file
I have a script where I need to get the text from line number $line in file $filename then save it to a var ($text) and then print it. For example, in the file lamb.txt (just an example file): Mary was a little lamb, whose fleece was as white as snow. I need to get line number 3 (fleece) and print it (print $text). How would I go about this? Andrew Conner (All apologies if this messes up and does a multi-post) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Printing line x in a file
On Sat, 11 May 2002, Andrew Conner wrote: I have a script where I need to get the text from line number $line in file $filename then save it to a var ($text) and then print it. For example, in the file lamb.txt (just an example file): Mary was a little lamb, whose fleece was as white as snow. I need to get line number 3 (fleece) and print it (print $text). How would I go about this? fopen() the file and call fgets() three times. The return from the third fgets call will contain the third line (including the terminating newline, so strip() it if you don't want that). miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php