PHP fpassthru() 函数

PHP 教程 · 2019-01-25 07:13:24

定义和用法

fpassthru() 函数从打开文件的当前位置开始读取所有数据,直到文件末尾(EOF),并向输出缓冲写结果。

该函数返回传递的字符数,如果失败则返回 FALSE。

语法


fpassthru(file)


参数 描述
file 必需。规定要读取的打开文件或资源。

提示和注释

注释:当在 Windows 系统的二进制文件中使用 fpassthru() 函数时,请牢记,必须以二进制的模式打开文件。

提示:如果您已经向文件写入数据,就必须调用 rewind() 来将文件指针指向文件头。

提示:如果您只想将文件的内容输出到输出缓冲,而不对它进行修改,请使用 readfile() 函数代替,这样可以省去 fopen() 调用。

实例 1


<?php
$file = fopen("test.txt","r");
// Read first line
fgets($file);
// Send rest of the file to the output buffer
echo fpassthru($file);
fclose($file);
?> 

上面的代码将输出:


There are three lines in this file.
This is the last line.59

59 指示被传递的字符数。

实例 2

转储 www 服务器的索引页:


<?php
$file = fopen("http://www.example.com","r");
fpassthru($file);
?>


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

查看所有标签

Python Machine Learning

Python Machine Learning

Sebastian Raschka / Packt Publishing - ebooks Account / 2015-9 / USD 44.99

About This Book Leverage Python' s most powerful open-source libraries for deep learning, data wrangling, and data visualization Learn effective strategies and best practices to improve and opti......一起来看看 《Python Machine Learning》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具