1. Computing & Technology

Discuss in my forum

Write to a file from PHP

By , About.com Guide

Rewrite Data
If we were to run this very same thing again only using different data, it would erase all of our current data, and replace it with the new data. Here is an example:

 <?php 
 $File = "YourFile.txt"; 
 $Handle = fopen($File, 'w');
 $Data = "John Henry\n"; 
 fwrite($Handle, $Data); 
 $Data = "Abigail Yearwood\n"; 
 fwrite($Handle, $Data); 
 print "Data Written"; 
 fclose($Handle); 
 ?>

The file we created, YourFile.txt, now contains this data:
John Henry
Abigail Yearwood

©2012 About.com. All rights reserved.

A part of The New York Times Company.