ftell
-
We use PHP’s
ftellfunction to return the current position of a file pointer.PHP
$f = fopen('/path/to/foobar', 'r'); fseek($f, 2); print ftell($f); //=> 2 fclose($f);
The
File#tellinstance method works exactly the same way.Ruby
File.open('/path/to/foobar', 'r') do |f| f.seek 2 puts f.tell #=> 2 end
Ruby IO objects also provide the aliases
posandpos=for working with the file pointer’s position. It’s a common Ruby idiom to use these instead ofseekandtell, but you’ll find both are widely used.Ruby
File.open('/path/to/foobar', 'r') do |f| f.pos = 2 puts f.pos #=> 2 end
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

