先讓我們了解下基本的文件操作函數
resource fopen($path,$math) 打開一個文件,$path 是路徑,$math是方法,返回一個資源句柄
string fgets ( resource $handle
[, int $length
] ) 從文件指針中讀取一行,$handle是資源句柄,返回一行文本內容
bool feof ( resource $handle
) 函數檢測是否已到達文件末尾 ,返回
ceshi.txt 文件內容
111111111111111 22222222222222 33333333333333 44444444444444 55555555555555 66666666666666
$handle = fopen('./ceshi.txt',"r");//以只讀方式打開一個文件 $i = 0; while(!feof($handle)){//函數檢測是否已到達文件末尾 if(fgets($handle)){// 從文件指針中讀取一行 $i++; }; } echo $i;//6 fclose($handle);