[英]I want to only read specific line from my text file with PHP
我有一個包含數據的文本文件,例如;
something1
something2
something3
something4
我需要獲取第四行的數據並在php中回顯它。
我從網上嘗試過代碼,但無法正常工作。
謝謝。
<?php
echo file("txtfile")['3'];
?>
這應該可以工作,它逐行讀取文件並在第三行中斷。
<?php
$file = fopen("test.txt","r");
$i =0;
while(! feof($file))
{
if($i==3){
echo fgets($file). "<br />";
break;
}
$i++;
}
fclose($file);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.