PHP fseek() function and example


 

PHP fseek() function and example

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

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

Ads