View Full Version : Reading a certain line of a text file
Phantom
05-09-2003, 11:53 PM
How would you read a certain line of a text file? Like if I wanted to read the file, and only print line 2 - no other lines.
firepages
05-10-2003, 01:32 AM
2 ways that I know , easiest is ...
<?
$yaks=file('text.txt');
echo $text[2];
?>
you can also fopen the file and set the filepointer to a set position using fseek($bytes) and then fgets($fp,$bytes) , but unless you have a vary large file its frobably more hassle than its worth.
duniyadnd
05-10-2003, 05:29 AM
You must have rushed your coding firepages ;), its:
<?
$yaks=file('text.txt');
echo $yaks[2];
?>
Duniyadnd
firepages
05-10-2003, 01:33 PM
DOH ! - spot on, cheers !
Phantom
05-10-2003, 11:18 PM
That's what I thought, thanks :-)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.