PHP fgets()関数
❮PHPファイルシステムリファレンス例
開いているファイルから1行を読み取ります。
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
定義と使用法
fgets()関数は、開いているファイルから行を返します。
構文
fgets(file, length)
パラメータ値
Parameter | Description |
---|---|
file | Required. Specifies the open file to return a line from |
length | Optional. Specifies the number of bytes to read. Reading stops when length-1 bytes have been reached, or when a new line occurs, or on EOF. If no length is specified, it reads until end of the line |
技術的な詳細
戻り値: | 成功した場合はファイルから1行が読み取られ、EOFまたはエラーの場合はFALSEが読み取られます。 |
---|---|
PHPバージョン: | 4.0以降 |
バイナリセーフ: | はい、PHP4.3では |
その他の例
例
開いているファイルを1行ずつ読み取ります。
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
❮PHPファイルシステムリファレンス