PHP fwrite() Function & example


 

PHP fwrite() Function & example

This segment of the PHP tutorial illustrates the use of file handling function fwrite() and its example

This segment of the PHP tutorial illustrates the use of file handling function fwrite() and its example

Syntax

int fwrite ( file_handle ,data_string [,length ] )

  • fwrite() function writes to the file with the given data string by using the file handle
  • It writes up to the given length argument.
  • It returns the no of bytes written to the file.
  • It returns FALSE if the file doesn't exist or if the file is opened in read form

Example of PHP fwrite() Function

Code
<?php

    $file
=fopen("aa.txt","a+");
    echo
file_get_contents("aa.txt");
    fwrite($file,"\n so have a behavour of the human being ");
    echo
"<br>".file_get_contents("aa.txt");
?>

Output
we all are human
we all are human so have a behaviour of the human being

Ads