file

(PHP 3, PHP 4 >= 4.0.0)

file -- ファイル全体を読み込んで配列に格納する

説明

array file (string filename, int [use_include_path])

readfile()と同じですが、file() はファイルを配列に入れて返すところが異なります。 配列の各要素はファイルの各行に対応します。改行記号はついたままと なります。

オプションの2番目の引数を使用して、これに"1"を設定することにより、 include_path のファイルの検索も行うことができます。


<?php
// Webページを配列として取得し、出力します。
$fcontents = file ('http://www.php.net');
while (list ($line_num, $line) = each ($fcontents)) {
   echo "<b>Line $line_num:</b> " . htmlspecialchars ($line) . "<br>\n";
}

// Webページを文字列として取得します。
$fcontents = join ( '', file ( 'http://www.php.net'));
?>
      

readfile(),fopen(), fsockopen(),popen()も参照下 さい。