PHP File Create/Write

The fwrite() function isused to write data into a file. The basic syntax of fwrite() is :
 fwrite(file_pointer, string)
Where the first argument is the file pointer or file handle, and the second argument string is nothing but the string we want to write into the file. Lets see the below example :
<?php

  $file = "file.txt";

  $myfile = fopen($file, "w") or die("Error : Cannot open the file.");     
  $str = "Hello world This is the string.";
  fwrite($myfile, $str) or die("Error : cannot write the file.");
  fclose($myfile);
  echo "Data written successfully to the file : $file";

?>
Output :

Data written successfully to the file : file.txt

Next Topic :