PHP:从文件读取特定行
问题描述:
我正在尝试使用php从文本文件中读取特定行. 这是文本文件:
I'm trying to read a specific line from a text file using php. Here's the text file:
foo
foo2
我如何使用php获取第二行的内容? 这将返回第一行:
How would I get the content of the second line using php? This returns the first line:
<?php
$myFile = "4-24-11.txt";
$fh = fopen($myFile, 'r');
$theData = fgets($fh);
fclose($fh);
echo $theData;
?>
..但是我需要第二个.
..but I need the second.
任何帮助将不胜感激
答
$myFile = "4-24-11.txt";
$lines = file($myFile);//file in to an array
echo $lines[1]; //line 2