本文介绍了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
这篇关于PHP:从文件中读取特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!