test1.txt文件內(nèi)容如下:this is my first day come in island.this is my first day come in island.this is my first day come in island.this is my first day come in island.我的PHP文件——filesystem.php文件內(nèi)容如下:$file = fopen("test1.txt","r");echo "<br>";while(!feof($file)){ echo fgetc($file); if(fgetc($file)==""){ echo "<br>"; }}fclose($file);在瀏覽器的輸出如下:ti sm is a oei sad ti sm is a oei sad ti sm is a oei sad ti sm is a oei sad 請問這是什么情況?
1 回答

忽然笑
TA貢獻1806條經(jīng)驗 獲得超5個贊
PHP code?
$root = $_SERVER['DOCUMENT_ROOT'];
$file = fopen("$root/php_02/123.txt", "rb");
while(!feof($file)){
$char = fgetc($file);
if(!feof($file)):
echo $char == '\n'?'<br>':$char;
endif;
}
fclose($file);
書上說,fgetc函數(shù)會返回EOF,因此在循環(huán)內(nèi)部用feof函數(shù)判斷是否達到文件結束,如果到達就不回顯在瀏覽器上。
我就有個疑問,
PHP code?
$char = fgetc($file);
- 1 回答
- 0 關注
- 93 瀏覽
添加回答
舉報
0/150
提交
取消