当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > fpassthru() 函数

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 fpassthru() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 509 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The fpassthru() function reads all data from the current position in an open file, until EOF, and writes the result to the output buffer.
fpassthru()函数的作用是:读取一个文件从当前位置开始的所有数据,直到EOF,并把结果写进输出缓冲器[output buffer]里。

This function returns the number of characters passed or FALSE on failure.
这个函数返回了传递的字符数量;如果执行失败将返回False。

Syntax
语法

fpassthru(file)

Parameter参数 Description描述
file Required. Specifies the open file or resource to read from
必要参数。指定需要打开的文件或源代码


Tips and Notes
提示和注意点

Note: When using fpassthru() on a binary file on Windows, remember to open the file in binary mode.
注意:当在Windows的二进制文件中使用fpassthru()函数时,请牢记,必须以二进制的模式打开文件。

Tip: Call rewind() to set the file pointer to the beginning of the file if you have already written to the file.
提示:如果你已将内容写进文件,那么你可以使用rewind()函数将文件指针设置在文件的开头。

Tip: If you just want to dump the contents of a file to the output buffer, without first modifying it, use the readfile() function instead.
提示:如果你想将文件的内容输出到输出缓冲器[out buffer],而对它进行修改,那么,你可以使用readfile()函数代替fpassthru()函数。


Example 1
案例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);
?> 

The output of the code above could be:
上述代码将输出下面的结果:

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

59 indicates the number of characters passed.
数字“59”表示总共传递的字符数量


Example 2
案例2

Dump index page of a www server:
清除www服务器的索引页:

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

评论 (0) All

登陆 | 还没注册?