<?php?
//首先采用“fopen”函數(shù)打開文件,得到返回值的就是資源類型。
$file_handle?=?fopen("/data/webroot/resource/php/f.txt","r");
if?($file_handle){
//接著采用while循環(huán)(后面語言結(jié)構(gòu)語句中的循環(huán)結(jié)構(gòu)會詳細(xì)介紹)一行行地讀取文件,然后輸出每行的文字
while?(!feof($file_handle))?{?//判斷是否到最后一行
$line?=?fgets($file_handle);?//讀取一行文本
echo?$line;?//輸出一行文本
echo?"<br?/>";?//換行
}
}
fclose($file_handle);//關(guān)閉文件
?>
輸出結(jié)果如下:
Warning:?fopen(/webroot/resource/php/f.txt):?failed?to?open?stream:?No?such?file?or?directory?in?/54/754/CCfs/index.php?on?line?3
Warning:?fclose()?expects?parameter?1?to?be?resource,?boolean?given?in?/54/754/CCfs/index.php?on?line?12
- 2 回答
- 0 關(guān)注
- 1418 瀏覽
添加回答
舉報
0/150
提交
取消