当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > fpassthru() 函数
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。
fpassthru(file) |
Parameter参数 | Description描述 |
---|---|
file | Required. Specifies the open file or resource to read from 必要参数。指定需要打开的文件或源代码 |
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()函数。
<?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”表示总共传递的字符数量
Dump index page of a www server:
清除www服务器的索引页:
<?php $file = fopen("http://www.example.com","r"); fpassthru($file); ?> |