downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

rmdir> <rename
[edit] Last updated: Fri, 17 May 2013

view this page in

rewind

(PHP 4, PHP 5)

rewindファイルポインタの位置を先頭に戻す

説明

bool rewind ( resource $handle )

handle のファイル位置指示子を、 ファイルストリームの先頭にセットします。

注意:

追記モード ("a" もしくは "a+") でファイルをオープンした場合、 ファイル位置によらずファイルに書き込まれるデータは常に追加されます。

パラメータ

handle

ファイルポインタは有効なものでなければならず、 また fopen() で正常にオープンされたファイルを指している必要があります。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例1 rewind() での上書きの例

<?php
$handle 
fopen('output.txt''r+');

fwrite($handle'Really long sentence.');
rewind($handle);
fwrite($handle'Foo');
rewind($handle);

echo 
fread($handlefilesize('output.txt'));

fclose($handle);
?>

上の例の出力は、 たとえば以下のようになります。

Foolly long sentence.

参考

  • fread() - バイナリセーフなファイルの読み込み
  • fseek() - ファイルポインタを移動する
  • ftell() - ファイルの読み書き用ポインタの現在位置を返す
  • fwrite() - バイナリセーフなファイル書き込み処理



add a note add a note User Contributed Notes rewind - [2 notes]
up
2
MagicalTux at kinoko dot fr
5 years ago
Note that rewind($fd) is exactly the same as fseek($fd, 0, SEEK_SET)

rewind() just moves the location inside the file to the beginning, nothing more. Check if your stream is "seekable" before planning to use fseek/rewind.
up
-2
evan at ozhiker dot no_spam dot com
8 years ago
As with fseek(), the rewind() function may not be used on file pointers returned by fopen() if they use the "http://" or "ftp://" formats.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites