if (feof($file)) echo "End of file";逐行读取文件
fgets() 函数用于从文件中逐行读取文件。
注释:在调用该函数之后,文件指针会移动到下一行。
例子
下面的例子逐行读取文件,直到文件末端为止:
<?php
$file = fopen("welcome.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>逐字符读取文件
fgetc() 函数用于从文件逐字符地读取文件。
注释:在调用该函数之后,文件指针会移动到下一个字符。
例子
下面的例子逐字符地读取文件,直到文件末端为止:
<?php
$file=fopen("welcome.txt","r") or exit("Unable to open file!");
while (!feof($file))
{
echo fgetc($file);
}
fclose($file);
?>
本文由BR2 整理
通辽权威妇科专家在线咨询http://www.tlmly.com
通辽宫颈疾病http://www.tlmly.com/DepartList.aspx?d=KS-003 转载请标明