Writing and Appending to a File : fputs « File Directory « PHP






Writing and Appending to a File

 
<html>
<head>
<title>Writing and Appending to a File</title>
</head>
<body>
<div>
<?php
$filename = "data.txt";
print "Writing to $filename<br/>";
$fp = fopen ( $filename, "w" ) or die ( "Couldn't open $filename" );
fwrite ( $fp, "Hello world\n" );
fclose ( $fp );
print "Appending to $filename<br/>";
$fp = fopen ( $filename, "a" ) or die ( "Couldn't open $filename" );
fputs ( $fp, "And another thing\n" );
fclose ( $fp );
?>
</div>
</body>
</html>
  
  








Related examples in the same category

1.A Simple Text-File Hit Counter
2.Using the fputs() Function
3.Storing data on a remote server