因此,我使用 while 循环和数组从文本文件中获取内容,然后将其回显。它的工作原理是一个问题,即最后一行:
First name: john Last name: paul Age: 44
First name: sam Last name: smith Age: 22
First name: jim Last name: bob Age: 33
First name: Last name: Age:
我的问题是如果它位于文件末尾,为什么它会再次循环,我如何摆脱最后一行?
<?php
$fileread = fopen("textfile.txt", "r");
while (!feof($fileread)){
$list = fgets($fileread);
$arrayinfo = explode(",", $list);
echo "<b>First name: </b> " . $arrayinfo[0] . " " . "<b>Last name: </b>" . $arrayinfo[1]. " " . "<b>Age: </b>" . $arrayinfo[2] . "<br>";
}
fclose($fileread);
?>