write info to a txt file
Posted: Sat Jan 05, 2008 7:37 am
basically its dead simple all I want to do is write to a text file! The code is below, the problem isn't that I cant write to the file but why is it not adding the data to the end of the file?
The code is the simplified test Im using!
This returns:
Data in file : This is my initial text New text added
Surely there is meant to be a line break between "text" and "New" !
The code is the simplified test Im using!
Code: Select all
<?
function write_file($filename,$newdata) {
$f=fopen($filename,"w");
fwrite($f,$newdata);
fclose($f);
}
function append_file($filename,$newdata) {
$f=fopen($filename,"a");
fwrite($f,$newdata);
fclose($f);
}
function read_file($filename) {
$f=fopen($filename,"r");
$data=fread($f,filesize($filename));
fclose($f);
return $data;
}
write_file("test.txt","This is my initial text\n");
append_file("test.txt","New text added\n");
$data=read_file("test.txt");
echo "Data in file : <b>$data</b>";
?>Data in file : This is my initial text New text added
Surely there is meant to be a line break between "text" and "New" !