answersLogoWhite

0

Oh this is easy =P

Lets say or file is "file.txt"

$fopen = fopen('file.txt','r+'); // Open the file with read and write permissions. However, this will write overwrite the contents of the file when written. To fix it, change r+ to a+.
$write = "Message to be written";
fwrite($fopen,$message); // Writes the message ($message) to the file. $fopen picks the file.
fclose($fopen); // Closes the file.
?>

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
BeauBeau
You're doing better than you think!
Chat with Beau
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine

Add your answer:

Earn +20 pts
Q: Write a PHP program to read and write a text file?
Write your answer...
Submit
Still have questions?
magnify glass
imp