PHP Doku:: Seek to a position - splfileobject.fseek.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzSonstige GrunderweiterungenStandard PHP Library (SPL)DateibehandlungThe SplFileObject classSplFileObject::fseek

Ein Service von Reinhard Neidl - Webprogrammierung.

The SplFileObject class

<<SplFileObject::fscanf

SplFileObject::fstat>>

SplFileObject::fseek

(PHP 5 >= 5.1.0)

SplFileObject::fseekSeek to a position

Beschreibung

public int SplFileObject::fseek ( int $offset [, int $whence = SEEK_SET ] )

Seek to a position in the file measured in bytes from the beginning of the file, obtained by adding offset to the position specified by whence.

Parameter-Liste

offset

The offset. A negative value can be used to move backwards through the file which is useful when SEEK_END is used as the whence value.

whence

whence values are:

  • SEEK_SET - Set position equal to offset bytes.
  • SEEK_CUR - Set position to current location plus offset.
  • SEEK_END - Set position to end-of-file plus offset.

If whence is not specified, it is assumed to be SEEK_SET.

Rückgabewerte

Returns 0 if the seek was successful, -1 otherwise. Note that seeking past EOF is not considered an error.

Beispiele

Beispiel #1 SplFileObject::fseek() example

<?php
$file 
= new SplFileInfo("somefile.txt");

// Read first line
$data $file->fgets();

// Move back to the beginning of the file
// Same as $file->rewind();
$file->fseek(0);
?>

Siehe auch

  • fseek() - Positioniert den Dateizeiger


Keine BenutzerBeiträge.
- Beiträge aktualisieren...



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)