fgets() and fread() - What is the difference?(fgets() 和 fread() - 有什么区别?)
问题描述
我了解 fgets() 之间的区别 和 fgetss() 但我不明白 之间的区别fgets() 和 fread(),有人可以澄清一下这个主题吗?哪个更快?谢谢!
I understand the differences between fgets() and fgetss() but I don't get the difference between fgets() and fread(), can someone please clarify this subject? Which one is faster? Thanks!
推荐答案
fgets 读取一行——即它将在换行符处停止.
fgets reads a line -- i.e. it will stop at a newline.
fread 读取原始数据——它将在指定的(或默认)字节数后停止,独立于可能存在或不存在的任何换行符.
fread reads raw data -- it will stop after a specified (or default) number of bytes, independently of any newline that might or might not be present.
速度不是使用一个而不是另一个的理由,因为这两个功能只是不做同样的事情:
Speed is not a reason to use one over the other, as those two functions just don't do the same thing :
- 如果您想从文本文件中读取一行,请使用
fgets - 如果您想从文件中读取一些数据(不一定是一行),请使用
fread.
这篇关于fgets() 和 fread() - 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:fgets() 和 fread() - 有什么区别?
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
