Posted on 2012-03-08 22:48
hoshelly 閱讀(183)
評(píng)論(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)時(shí)
{
echo fgets($file)."<br/>";//從文件中逐行讀取文件
}
if(feof($file)) echo "End of file";
fclose($file);//關(guān)閉文件
?>
</body>
</html>
//-----------------------------------------------------------------------------------------------------------------------------------------------------
fopen只是“打開”一個(gè)文件,并保存為一個(gè)資源變量。 這個(gè)資源變量里面并不包括文件的內(nèi)容。 如果只是想顯示文件內(nèi)容,可用下面的語句: require_once "welcome.txt";
另外還有一個(gè)函數(shù):
fgetc() 函數(shù):用于從文件逐字符地讀取文件。 注釋:在調(diào)用該函數(shù)之后,文件指針會(huì)移動(dòng)到下一個(gè)字符。