stream_get_contentsとは? わかりやすく解説

Weblio 辞書 > コンピュータ > PHP関数リファレンス > stream_get_contentsの意味・解説 

stream_get_contents

(PHP 5)
stream_get_contents — 残りのストリームを文字列に読み込む

説明

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

パラメータ

handle (resource)
ストリームリソース(例: fopen() の返す値)。
maxlength (integer)
読み込む最大バイト数。デフォルトは -1 (バッファの残りのデータをすべて読み込む)。
offset (integer)
読み込みを開始する前に移動する位置。PHP 5.1.0 で追加されました。

返り値

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

例 2232. stream_get_contents() の例
<?php

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

   fclose($stream);
}


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

   fclose($stream);
}

?>


参考

fgets()
fread()
fpassthru()

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



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「stream_get_contents」の関連用語

stream_get_contentsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



stream_get_contentsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
PHP Documentation GroupPHP Documentation Group
Copyright © 1997 - 2025 by the PHP Documentation Group.

©2025 GRAS Group, Inc.RSS