位置: 编程技术 - 正文

PHP:fread()的用法_Filesystem函数(php fopen())

编辑:rootadmin
fread

推荐整理分享PHP:fread()的用法_Filesystem函数(php fopen()),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:phpforeach用法,php中fwrite函数的用法,php中fwrite函数的用法,phpforeach用法,php fscanf,php readfile,php readfile,php fscanf,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4, PHP 5)

fread — 读取文件(可安全用于二进制文件)

说明 string fread ( resource $handle , int $length )

fread() 从文件指针 handle 读取最多 length 个字节。 该函数在遇上以下几种情况时停止读取文件: 读取了 length 个字节 到达了文件末尾(EOF) a packet becomes available or the socket timeout occurs (for network streams) if the stream is read buffered and it does not represent a plain file, at most one read of up to a number of bytes equal to the chunk size (usually ) is made; depending on the previously buffered data, the size of the returned data may be larger than the chunk size.

参数

handle

文件系统指针,是典型地由fopen() 创建的 resource(资源)。

length

最多读取 length 个字节。

返回值

返回所读取的字符串, 或者在失败时返回 FALSE。

范例

Example #1 一个简单的 fread() 例子

<?php//getcontentsofafileintoastring$filename="/usr/local/something.txt";$handle=fopen($filename,"r");$contents=fread($handle,filesize($filename));fclose($handle);?>

PHP:fread()的用法_Filesystem函数(php fopen())

Example #2 Binary fread() example

Warning

在区分二进制文件和文本文件的系统上(如 Windows)打开文件时,fopen() 函数的 mode 参数要加上 &#;b&#;。

<?php$filename="c:\files\somepic.gif";$handle=fopen($filename,"rb");$contents=fread($handle,filesize($filename));fclose($handle);?>

Example #3 Remote fread() examples

Warning

当从任何不是普通本地文件读取时,例如在读取从远程文件或 popen() 以及 fsockopen() 返回的流时,读取会在一个包可用之后停止。这意味着应该如下例所示将数据收集起来合并成大块。

<?php//对PHP5及更高版本$handle=fopen("

注释

Note:

如果只是想将一个文件的内容读入到一个字符串中,用 file_get_contents(),它的性能比上面的代码好得多。

Note:

Note that fread() reads from the current position of the file pointer. Use ftell() to find the current position of the pointer and rewind() to rewind the pointer position.

参见

fwrite() - 写入文件(可安全用于二进制文件) fopen() - 打开文件或者 URL fsockopen() - 打开一个网络连接或者一个Unix套接字连接 popen() - 打开进程文件指针 fgets() - 从文件指针中读取一行 fgetss() - 从文件指针中读取一行并过滤掉 HTML 标记 fscanf() - 从文件中格式化输入 file() - 把整个文件读入一个数组中 fpassthru() - 输出文件指针处的所有剩余数据 ftell() - 返回文件指针读/写的位置 rewind() - 倒回文件指针的位置

PHP:ftruncate()的用法_Filesystem函数 ftruncate(PHP4,PHP5)ftruncate将文件截断到给定的长度说明boolftruncate(resource$handle,int$size)接受文件指针handle作为参数,并将文件大小截取为size。参数handle文件

PHP:fopen()的用法_Filesystem函数 fopen(PHP4,PHP5)fopen打开文件或者URL说明resourcefopen(string$filename,string$mode[,bool$use_include_path=false[,resource$context]])fopen()将filename指定的名字资源绑定到一个流上

PHP:fseek()的用法_Filesystem函数 fseek(PHP4,PHP5)fseek在文件指针中定位说明intfseek(resource$handle,int$offset[,int$whence=SEEK_SET])在与handle关联的文件中设定文件指针位置。新位置从文件头开始以字

本文链接地址:https://www.jiuchutong.com/biancheng/285205.html 转载请保留说明!

上一篇:PHP:fwrite()的用法_Filesystem函数(php iswriteable)

下一篇:PHP:ftruncate()的用法_Filesystem函数(php traits)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络