PHP fseek() Functie
❮ Referentie voor PHP-bestandssysteemVoorbeeld
Lees de eerste regel van het geopende bestand en verplaats vervolgens de bestandsaanwijzer terug naar het begin van het bestand:
<?php
$file = fopen("test.txt","r");
// Read first line
echo fgets($file);
// Move back to beginning of file
fseek($file,0);
fclose($file);
?>
Definitie en gebruik
De functie fseek() zoekt in een geopend bestand.
Deze functie verplaatst de bestandsaanwijzer van zijn huidige positie naar een nieuwe positie, vooruit of achteruit, gespecificeerd door het aantal bytes.
Tip: U kunt de huidige positie vinden door ftell() te gebruiken!
Syntaxis
fseek(file, offset, whence)
Parameterwaarden
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:
|
Technische details
Winstwaarde: | 0 bij succes, anders -1 |
---|---|
PHP-versie: | 4.0+ |
❮ Referentie voor PHP-bestandssysteem