<?PHP/*The PHP file creation/write fopen () function is also used to create files. It may be a bit confusing, but in PHP, the function used to create the file is the same as the open file. If you open a file that does not exist with fopen (), this function creates the file, assuming that the file is opened to write (W) or increase (a). The PHP write file-fwrite () fwrite () function is used to write to the file. The first parameter of Fwrite () contains the file name of the file to be written, and the second argument is the string to be written. PHP Overlay (overwriting) if "Newfile.txt" now contains some data, we can show what happens when we write to an existing file. All existing data is erased and starts with a new file. */ Header("content-type:text/html; Charset=utf-8 "); $myfile=fopen("Testfile.txt", "w") or die("Unable to open file!"); $txt= "Bill Gates \ n"; fwrite($myfile,$txt); $txt= "Server jobs \ n"; fwrite($myfile,$txt); fclose($myfile); $myfile 1=fopen("Testfile.txt", "R"); while(!feof($myfile 1)){ Echo fgets($myfile 1)." <br> "; } $myfile 2=fopen("Testfile.txt", "w") or die("Unable to open file!"); $txt= "Mickey mouse\n"; fwrite($myfile 2,$txt); $txt= "Minnie mouse\n"; fwrite($myfile 2,$txt); fclose($myfile 2); $myfile 3=fopen("Testfile.txt", "R"); while(!feof($myfile 3)){ Echo fgets($myfile 3)." <br> "; }?>
PHP File creation/writing