Certified PHP Developer Learning Resources Writing to a file

Writing to a file

Write to a File
copy$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
$data = 'This is the data';
fwrite($handle, $data);

Check end of file - The feof() function checks if the "end-of-file" (EOF) has been reached. The feof() function is useful for looping through data of unknown length. PHP cannot read from files opened in w, a, and x mode! An example -
if (feof($file)) echo "End of file";

 For Support