PHP fgetc() 函数

PHP 教程 · 2019-01-24 20:13:10

定义和用法

fgetc() 函数从打开的文件中返回一个单一的字符。

语法


fgetc(file)


参数 描述
file 必需。规定要检查的文件。

提示和注释

注释:该函数处理大文件非常缓慢,所以它不用于处理大文件。如果您需要从一个大文件依次读取一个字符,请使用 fgets() 依次读取一行数据,然后使用 fgetc() 依次处理行数据。

实例 1


<?php
$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);
?>

上面的代码将输出:


Hello, this is a test file.


点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Foundations of PEAR

Foundations of PEAR

Good, Nathan A./ Kent, Allan / Springer-Verlag New York Inc / 2006-11 / $ 50.84

PEAR, the PHP Extension and Application Repository, is a bountiful resource for any PHP developer. Within its confines lie the tools that you need to do your job more quickly and efficiently. You need......一起来看看 《Foundations of PEAR》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具