Sang Froid Sang Froid - 1 year ago 120
PHP Question

PHP: Read Specific Line From File

I'm trying to read a specific line from a text file using php.
Here's the text file:


How would I get the content of the second line using php?
This returns the first line:

$myFile = "4-24-11.txt";
$fh = fopen($myFile, 'r');
$theData = fgets($fh);
echo $theData;

..but I need the second.

Any help would be greatly appreciated

Answer Source
$myFile = "4-24-11.txt";
$lines = file($myFile);//file in to an array
echo $lines[1]; //line 2

file — Reads entire file into an array

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download