September 2001
Intermediate to advanced
768 pages
32h 45m
English
int fseek(resource file_handle, int offset)
Seeks in a file.
Returns:
0 on success; -1 on error
Description:
Moves file pointer from its current position to a new position, forward or backward, specified by the number of bytes. You can determine the current position by using ftell(). This function doesn’t operate on file pointers opened using FTP or HTTP. Note that seeking past EOF is not considered an error, but the file position is changed (even if invalid).When trying to seek before the start of the file, fseek() fails.
Example:
$fh = fopen("test.txt", "r");
$a = 0;
while(!feof($fh))
{
fseek($fh, $a);
echo (fgetc($fh));
$a = $a + 2;
}
fclose($fh);
|
Read now
Unlock full access