PHP fread()関数
❮PHPファイルシステムリファレンス例
開いているファイルから10バイトを読み取ります。
<?php
$file = fopen("test.txt","r");
fread($file,"10");
fclose($file);
?>
定義と使用法
fread()は開いているファイルから読み取ります。
関数は、ファイルの終わりまたは指定された長さに達すると、どちらか早い方で停止します。
構文
fread(file, length)
パラメータ値
Parameter | Description |
---|---|
file | Required. Specifies the open file to read from |
length | Required. Specifies the maximum number of bytes to read |
技術的な詳細
戻り値: | 読み取り文字列、失敗した場合はFALSE |
---|---|
PHPバージョン: | 4.0以降 |
バイナリセーフ: | はい |
その他の例
例
ファイル全体を読む:
<?php
$file = fopen("test.txt","r");
fread($file,filesize("test.txt"));
fclose($file);
?>
❮PHPファイルシステムリファレンス