PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a php script that takes input from an html form and puts it in a text file. Basically its kind of like a web-log so i want the newest entry to be at the TOp of the text file, not at the bottom. Heres my source:
<?php
$formating = "<p>testformat<p>";
// Open the file
$fp = fopen("test.html", "a+");
// Write the data to the file
rewind($fp);
fwrite($fp, $formatting);
fwrite($fp, $newsupdate);
// Close the file
fclose($fp);
?>
As you can see its just a simple script. Ive tried to use the rewind command but it still appeneds to the end of the file. I must not be using it correctly.
The append flag automatically appends to the end of the file. Is it important to add onto the beginning? You could read in the last N lines then reverse their order to mimic that? The only way to push strings infront of a file is to read in the file, concate your string to it and write the file back
I did think about trying to read then file and then reserve their order, but i didnt know where to start sicne im a php novice. How would i go about doing something like that? Would it be complex?