gpt4 book ai didi

PHP:从文件中读取特定行

转载 作者:IT王子 更新时间:2023-10-28 23:55:05 24 4
gpt4 key购买 nike

我正在尝试使用 php 从文本文件中读取特定行。这是文本文件:

foo  
foo2

我如何使用 php 获取第二行的内容?这将返回第一行:

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

..但我需要第二个。

任何帮助将不胜感激

最佳答案

$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

关于PHP:从文件中读取特定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5775452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com