PHP fgets()函数
fgets() 函数可以从打开的文件中返回一行。该函数在指定的长度或EOF(以先到者为准)到达新行时停止返回,并在失败时返回 false。
语法
string fgets ( resource handle [, intlength ] )
这个函数可以从指向的文件中返回一个长度不超过length-1个字节的字符串。
示例1
<?php
file = fopen("/PhpProject/sample.txt", "r");
echo fgets(file);
fclose($file);
?>
输出
tutorialspoint
示例2
<?php
file = fopen("/PhpProject/sample.txt", "r");
while(! feof(file)) {
echo fgets(file). "\n";
}
fclose(file);
?>
输出
tutorialspoint
tutorix