Example of fputs() function in PHP


 

Example of fputs() function in PHP

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

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

Ads