PHP fseek()関数
❮PHPファイルシステムリファレンス例
開いているファイルから最初の行を読み取り、ファイルポインタをファイルの先頭に戻します。
<?php
$file = fopen("test.txt","r");
// Read first line
echo fgets($file);
// Move back to beginning of file
fseek($file,0);
fclose($file);
?>
定義と使用法
fseek()関数は、開いているファイルをシークします。
この関数は、ファイルポインタを現在の位置から、バイト数で指定された前方または後方の新しい位置に移動します。
ヒント: ftell()を使用すると、現在の位置を見つけることができます。
構文
fseek(file, offset, whence)
パラメータ値
Parameter | Description |
---|---|
file | Required. Specifies the open file to seek in |
offset | Required. Specifies the new position (measured in bytes from the beginning of the file) |
whence | Optional. Possible values:
|
技術的な詳細
戻り値: | 成功した場合は0、それ以外の場合は-1 |
---|---|
PHPバージョン: | 4.0以降 |
❮PHPファイルシステムリファレンス