Share on Google+Share on Google+

Example of fputs() function in PHP

Advertisement
In this segment of PHP tutorial, we will learn how to use the fputs() file handling function and its example.

Syntax

  • It writes the given string or the variable to the file by using the file handler.
  • It writes the data only up to the given length and stop writing after that.
  • But if length is not given it will write all the given data.


Example of PHP fputs() Function

<?php
    $file
=fopen("c:/rose1/ram.txt","r");

      echo
"before using fputs<br>";
      echo
fread($file,100);
    fclose($file);

      echo
"<br>after using fputs<br>";
    $file1
=fopen("c:/rose1/ram.txt","w");
      fputs($file1,"we all are indian");
    fclose($file1);

    $file2=fopen("c:/rose1/ram.txt","r");
      echo
"<br>";
    echo
fread($file2,100);
?>

Output

before using fputs
ram is a good boy
after using fputs
we all are indian

Advertisements

Advertisement

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.