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.
(PHP 4, PHP 5, PHP 7, PHP 8)
rewind — Setzt die Position eines Dateizeigers auf den Anfang
$handle
) : bool
Setzt den Datei-Positions-Indikator für
handle
an den Anfang des Dateistreams.
Hinweis:
Wurde die Datei im Anfüge-Modus ("a" oder "a+") geöffnet, werden unabhängig von der Position des Dateizeigers alle zu schreibenden Daten angehängt.
handle
Der Dateizeiger muss gültig sein und auf eine Datei zeigen, die zuvor erfolgreich durch fopen() geöffnet wurde.
Gibt bei Erfolg true
zurück. Im Fehlerfall wird false
zurückgegeben.
Beispiel #1 Beispiel zum Überschreiben mit rewind()
<?php
$handle = fopen('output.txt', 'r+');
fwrite($handle, 'Wirklich langer Satz.');
rewind($handle);
fwrite($handle, 'Foo');
rewind($handle);
echo fread($handle, filesize('output.txt'));
fclose($handle);
?>
Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:
Fooklich langer Satz.
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.