When writing to a file, the first thing you need to do is to open up the file. We do that with this code:
<?php
$File = "YourFile.txt";
$Handle = fopen($File, 'w');
?>
Now we can use the fwrite command to add data to our file. We would do this as shown below:
<?php
$File = "YourFile.txt";
$Handle = fopen($File, 'w');
$Data = "Jane Doe\n";
fwrite($Handle, $Data);
$Data = "Bilbo Jones\n";
fwrite($Handle, $Data);
print "Data Written";
fclose($Handle);
?>
At the end of the file we use fclose to close the file we have been working with. You may also notice we are using \n at the end of our data strings. The \n servers as a line break, like hitting the enter or return key on your keyboard.
You now have a file called YourFile.txt that contains the data:
Jane Doe
Bilbo Jones

