ストリーム 関数
PHP Manual

stream_get_contents

(PHP 5)

stream_get_contents残りのストリームを文字列に読み込む

説明

string stream_get_contents ( resource $handle [, int $maxlength= -1 [, int $offset= 0 ]] )

file_get_contents() と似ていますが、 stream_get_contents() は既にオープンしている ストリームリソースに対して操作を行います。そして、指定した offset から始まる最大 maxlength バイトのデータを取得して文字列に 保存します。

パラメータ

handle (resource)

ストリームリソース(例: fopen() の返す値)。

maxlength (integer)

読み込む最大バイト数。デフォルトは -1 (バッファの残りのデータをすべて読み込む)。

offset (integer)

読み込みを開始する前に移動する位置。PHP 5.1.0 で追加されました。

返り値

文字列を返します。失敗した場合は FALSE を返します。

例1 stream_get_contents() の例

<?php

if ($stream fopen('http://www.example.com''r')) {
    
// オフセット 10 から開始して、残りのすべてのページを表示します
    
echo stream_get_contents($stream, -110);

    
fclose($stream);
}


if (
$stream fopen('http://www.example.net''r')) {
    
// 最初の 5 バイトを表示します
    
echo stream_get_contents($stream5);

    
fclose($stream);
}

?>

参考

注意: この関数はバイナリデータに対応しています。


ストリーム 関数
PHP Manual
アダルトレンタルサーバー