PHP file_get_contents()関数
❮PHPファイルシステムリファレンス例
ファイルを文字列に読み込みます。
<?php
echo file_get_contents("test.txt");
?>
定義と使用法
file_get_contents()は、ファイルを文字列に読み込みます。
この関数は、ファイルの内容を文字列に読み込むための推奨される方法です。サーバーでサポートされている場合は、メモリマッピング技術を使用してパフォーマンスを向上させます。
構文
file_get_contents(path, include_path, context, start,
max_length)
パラメータ値
Parameter | Description |
---|---|
path | Required. Specifies the path to the file to read |
include_path | Optional. Set this parameter to '1' if you want to search for the file in the include_path (in php.ini) as well |
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. Can be skipped by using NULL. |
start | Optional. Specifies where in the file to start reading. Negative values count from the end of the file |
max_length | Optional. Specifies the maximum length of data read. Default is read to EOF |
技術的な詳細
戻り値: | 文字列内のファイル全体、失敗した場合はFALSE |
---|---|
PHPバージョン: | 4.3+ |
バイナリセーフ: | はい、PHP4.3では |
PHP変更ログ: | PHP7.1-開始パラメーターでの負の値のサポートPHP5.1-開始パラメーターとmax_lengthパラメーターを 追加しました |
❮PHPファイルシステムリファレンス