Posted on 2012-03-08 22:48
hoshelly 閱讀(182)
評論(0) 編輯 收藏 引用 所屬分類:
PHP
<html>
<body>
<?php
$file=fopen("welcome.txt","r") or exit("Unable to open file!");//open "welcom.txt"file, 只讀方式
while(!feof($file))//當(dāng)還未達(dá)到文件的末端(EOF)時
{
echo fgets($file)."<br/>";//從文件中逐行讀取文件
}
if(feof($file)) echo "End of file";
fclose($file);//關(guān)閉文件
?>
</body>
</html>
//-----------------------------------------------------------------------------------------------------------------------------------------------------
fopen只是“打開”一個文件,并保存為一個資源變量。 這個資源變量里面并不包括文件的內(nèi)容。 如果只是想顯示文件內(nèi)容,可用下面的語句: require_once "welcome.txt";
另外還有一個函數(shù):
fgetc() 函數(shù):用于從文件逐字符地讀取文件。 注釋:在調(diào)用該函數(shù)之后,文件指針會移動到下一個字符。