Forum und email

fgetc

(PHP 4, PHP 5)

fgetc — Gets character from file pointer

說明

string fgetc ( resource $handle )

Gets a character from the given file pointer.

參數

handle

檔案指標必須有效,並且必須指向一個由 fopen()fsockopen() 成功打開(但還沒有被 fclose() 關閉)的檔案。

Return值

Returns a string containing a single character read from the file pointed to by handle . Returns FALSE on EOF.

Warning

本函式可能回傳布林值 FALSE,但也可能回傳一個與 FALSE 等值的非布林值,例如 0 或者 ""。請參閱布林類型章節以獲取更多訊息。應使用 === 運算符來測試本函式的回傳值。

範例

Example#1 A fgetc() example

<?php
$fp 
fopen('somefile.txt''r');
if (!
$fp) {
    echo 
'Could not open file somefile.txt';
}
while (
false !== ($char fgetc($fp))) {
    echo 
"$char\n";
}
?>

註釋

Note: 本函式可安全用於二進位對象。