fgetc

(PHP 3, PHP 4, PHP 5)

fgetc -- 从文件指针中读取字符

说明

string fgetc ( resource handle )

返回一个包含有一个字符的字符串,该字符从 handle 指向的文件中得到。碰到 EOF 则返回 FALSE

文件指针必须是有效的,并且必须指向一个由 fopen()fsockopen() 成功打开的文件。

警告

本函数可能返回布尔值 FALSE,但也可能返回一个与 FALSE 等值的非布尔值,例如 0 或者 ""。请参阅布尔类型章节以获取更多信息。应使用 === 运算符来测试本函数的返回值。

例子 1. fgetc() 例子

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

注: 本函数可安全用于二进制对象。

参见 fread()fopen()popen()fsockopen()fgets()


add a note add a note User Contributed Notes
There are no user contributed notes for this page.