File handling in php allow us to make operation to write in a file .So we can write a new file or we can append text to an already existing file.For this we have fwrite() function in PHP.
Syntax is : -
fwrite(file,string,length);
parameters are:-
file - Required. it allow there is an open file we have to write to.
string - Required. It allow string to write in a opened file.
length - Optional. It allow the max limit of bytes to write in a file.
NOTE : - If there is third parameter included in the fwrite() function, then writing in a file will stop just after the given value of length parameter .
Example for writing in a file : -
<?php
$filename = "/home/user/guest/newfile.txt";
$file = fopen( $filename, "w" );
if( $file == false )
{
echo ( "Error in opening new file" );
exit();
}
fwrite( $file, "This is a simple test\n" );
fclose( $file );
?>
0 Comment(s)