Create File in PHP
To create a file in PHP fopen() function is used i.e., the function that is used to open a file is also used to create a file. If we use, fopen function() to open a file and file doesn't exist, it will create a new file.
For example:
$filename=fopen("demo.txt","w")
Write to File in PHP:
To write in a file in PHP fwrite() function is used. This function contains two parameters:
- first parameter is the name of the file to write to
- second parameter is the string to be written to the file.
For example:
<?php
$filename = fopen("demo.txt", "w") or die("Unable to open file!");
$filetxt = "Writing to a file in PHP\n";
fwrite($filename, $filetxt);
$filetxt = "Again writing to a file\n";
fwrite($filename, $filetxt);
fclose($filename);
?>
0 Comment(s)