fwrite example in php

The fwrite() is used to write the contents to text file.

Syntax:

fwrite($fp,’content’);

// content will be written $fp pointer and it will be written in data.txt.

Program: 

<?php
$fp = fopen('data.txt', 'w');
fwrite($fp, '1');
fwrite($fp, '23');
fclose($fp);
// the content of 'data.txt' is now 123 and not 23!
?>

 

Output:

fwrite

 

data.txt file:

data

// it will be written in the data.txt, which will be in the same location of php source file.

Thanks for reading this post……….!!!

472 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *