PHP fread() 函数

PHP 教程 · 2019-01-25 07:57:57

定义和用法

fread() 函数读取打开的文件。

函数会在到达指定长度或读到文件末尾(EOF)时(以先到者为准),停止运行。

该函数返回读取的字符串,如果失败则返回 FALSE。

语法

string fread ( resource $handle , int $length )

参数 描述
handle 文件系统指针,是典型地由 fopen() 创建的 resource(资源)。
length 必需。规定要读取的最大字节数。

提示和注释

提示:该函数是二进制安全的。(意思是二进制数据(如图像)和字符数据都可以使用此函数写入。)

实例 1

从文件中读取 10 个字节:


<?php
$file = fopen("test.txt","r");
$contents = fread($file,"10");
fclose($file);
?>


实例 2

读取整个文件:


<?php
$file = fopen("test.txt","r");
$contents = fread($file,filesize("test.txt"));
fclose($file);
?>


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

查看所有标签

Ruby Cookbook

Ruby Cookbook

Lucas Carlson、Leonard Richardson / O'Reilly Media / 2006-7-29 / USD 49.99

Do you want to push Ruby to its limits? The "Ruby Cookbook" is the most comprehensive problem-solving guide to today's hottest programming language. It gives you hundreds of solutions to real-world pr......一起来看看 《Ruby Cookbook》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码