stream_get_contents
(PHP 5, PHP 7)
stream_get_contents - 将一个流的其余部分读入一个字符串
描述
string stream_get_contents ( resource $handle [, int $maxlength = -1 [, int $offset = -1 ]] )
与file_get_contents()相同,不同之处在于stream_get_contents()在已打开的流资源上操作并返回字符串中的剩余内容,直到maxlength
字节并从指定位置开始offset
。
参数
handle
(resource)
流资源(例如,从fopen()返回)
maxlength
(integer)
要读取的最大字节数。默认为-1(读取所有剩余的缓冲区)。
offset
(integer)
阅读前寻找指定的偏移量。如果这个数字是负数,则不会发生寻找,并且读数将从当前位置开始。
返回值
返回一个字符串或FALSE
失败。
更新日志
Version | Description |
---|---|
5.1.0 | The offset was added. |
例子
示例#1 stream_get_contents()示例
<?php
if?($stream?=?fopen('http://www.example.com',?'r'))?{
????//?print?all?the?page?starting?at?the?offset?10
????echo?stream_get_contents($stream,?-1,?10);
????fclose($stream);
}
if?($stream?=?fopen('http://www.example.net',?'r'))?{
????//?print?the?first?5?bytes
????echo?stream_get_contents($stream,?5);
????fclose($stream);
}
?>
笔记
注意:此功能是二进制安全的。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com