Home arrow PHP arrow Page 2 - Handling File Data with PHP

Moving the File Pointer - PHP

In this fifth part of an eight-part series on working with file and operating systems with PHP, you'll learn how to read data from a file and move the file pointer. This article is excerpted from chapter 10 of the book Beginning PHP and PostgreSQL 8: From Novice to Professional, written by W. Jason Gilmore and Robert H. Treat (Apress; ISBN: 1590595475).

  1. Handling File Data with PHP
  2. Moving the File Pointer
By: Apress Publishing
Rating: starstarstarstarstar / 0
November 29, 2011

print this article



It's often useful to jump around within a file, reading from and writing to various locations. Several PHP functions are available for doing just this.


int fseek (resource handle, int offset [, int whence])

The fseek() function moves the handle's pointer to the location specified by offset. If the optional parameter whence is omitted, the position is set offset bytes from the beginning of the file. Otherwise, whence can be set to one of three possible values, which affect the pointer's position:

  1. SEEK_CUR: Sets the pointer position to the current position plus offset bytes.
  2. SEEK_END: Sets the pointer position to the EOF plus offset bytes. In this case, offset must be set to a negative value.
  3. SEEK_SET: Sets the pointer position to offset bytes. This has the same effect as omitting whence.


int ftell (resource handle)

The ftell() function retrieves the current position of the file pointer's offset within the resource specified by handle.


int rewind (resource handle)

The rewind() function moves the file pointer back to the beginning of the resource specified by handle.

Please check back for the continuation of this article.

>>> More PHP Articles          >>> More By Apress Publishing

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: