php fgetc()函数视频,PHP fgetc( )用法及代码示例

PHP中的fgetc()函数是一个内置函数,用于从打开的文件中返回单个字符。它用于从给定的文件指针获取字符。

要检查的文件用作fgetc()函数的参数,它从文件中返回一个包含单个字符的字符串作为参数。

用法:

fgetc($file)

参数:PHP中的fgetc()函数仅接受一个参数$file。它指定需要从中提取字符的文件。

返回值:它从文件中返回一个包含单个字符的字符串作为参数。

错误与异常:

该功能未针对大型文件进行优化,因为它一次只能读取一个字符,并且完全读取一个长文件可能要花费很多时间。

如果多次使用fgetc()函数,则必须清除缓冲区。

fgetc()函数返回布尔值False,但是很多时候它返回一个非布尔值,该值的值为False。

以下示例程序旨在说明fgetc()函数。

程序1::在下面的程序中,名为gfg.txt的文件包含以下文本。

This is the first line.

This is the second line.

This is the third line.

// file is opened using fopen() function

$my_file = fopen("gfg.txt", "rw");

// Prints a single character from the

// opened file pointer

echo fgetc($my_file);

// file is closed using fclose() function

fclose($my_file);

?>

输出:

T

程序2::在下面的程序中,名为gfg.txt的文件包含以下文本。

This is the first line.

This is the second line.

This is the third line.

// file is opened using fopen() function

$my_file = fopen("gfg.txt", "rw");

// prints single character at a time

// until end of file is reached

while (! feof ($my_file))

{

echo fgetc($my_file);

}

// file is closed using fclose() function

fclose($my_file);

?>

输出:

This is the first line.

This is the second line.

This is the third line.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值