Share on Google+Share on Google+

PHP fseek() function and example

Advertisement
In this segment of the PHP tutorial we will learn the fseek function of the file handling

Syntax

int fseek (file_handle ,offset [, whence ] )

  • It seeks the new position of the file pointer from old position.
  • Then using the new position it will work for all functions
  • It gives 0 if test succeeds and -1 of test gets failured
whence is optional. Its values are
  • SEEK_SET ( Default value,It makes position equal to offset),
  • SEEK_CUR (It makes position to current location with offset),
  • SEEK_END (Makes position to EOF with offset )


Example of PHP fseek() Function PHP

Code code for fseek() Function in PHP

<?php
$file
=fopen("roseindia.txt","r");
echo
fread($file,240);
echo
"<br><br>now position set to 40 bytes <br><br>";
fseek($file,40);
echo
fread($file,240);
?>

Output

This site contains many quality Java, JSP Tutorials, Hibernate Tutorials, Struts Tutorials, JSF Tutorials, RMI, MySQL Tutorials, Spring Tutorials, source codes and links to other java resources. We have large number of links to the tutorial

now position set to 40 bytes

P Tutorials, Hibernate Tutorials, Struts Tutorials, JSF Tutorials, RMI, MySQL Tutorials, Spring Tutorials, source codes and links to other java resources. We have large number of links to the tutorials on java which will help you learn java

Advertisements

Posted on: October 29, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.