PHP fgetc() 函數

定義和用法
fgetc() 函數從打開的檔中返回一個單一的字元。
語法
fgetc(file)
參數 | 描述 |
---|---|
file | 必需。規定要檢查的檔。 |
提示和注釋
注釋:該函數處理大檔非常緩慢,所以它不用於處理大檔。如果您需要從一個大檔依次讀取一個字元,請使用 fgets() 依次讀取一行數據,然後使用 fgetc() 依次處理行數據。
實例 1
<?php
$file = fopen("test2.txt","r");
echo fgetc($file);
fclose($file);
?>
$file = fopen("test2.txt","r");
echo fgetc($file);
fclose($file);
?>
上面的代碼將輸出:
H
實例 2
按字元讀取檔:
<?php
$file = fopen("test2.txt","r");
while (! feof ($file))
{
echo fgetc($file);
}
fclose($file);
?>
$file = fopen("test2.txt","r");
while (! feof ($file))
{
echo fgetc($file);
}
fclose($file);
?>
上面的代碼將輸出:
Hello, this is a test file.
