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

search for in the

rmdir> <rename
Last updated: Fri, 13 Nov 2009

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() - バイナリセーフなファイル書き込み処理



rmdir> <rename
Last updated: Fri, 13 Nov 2009
 
add a note add a note User Contributed Notes
rewind
MagicalTux at kinoko dot fr
27-Nov-2007 06:53
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.
berndt at www dot michael - berndt dot de
05-May-2005 07:27
evan at ozhiker dot no_spam dot com
05-Aug-2004 03:56
As with fseek(), the rewind() function may not be used on file pointers returned by fopen() if they use the "http://" or "ftp://" formats.

rmdir> <rename
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites