Hi, I’m trying to reverse the lines in my text file, here is my code:
$filename = "comments.txt";
$date = date('jS F Y');
$time = date('h:i a');
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$message = $_POST['message'];
$submit = $_POST['submit'];
// when user submits the form
if($submit=="submit") {
// open text file
$fp=fopen($filename, 'a+');
// then using this format
$fstring="||" . $date . "||" . $time . "||" . $name . "||" . $email . "||" . $website . "||" . $message . "
\r";
// write the comment
fwrite($fp, $fstring);
// close text file
fclose($fp);
};
This is what I have come up with:
fputs ($fp, array_reverse ($fstring));
I have added it here:
// open text file
$fp=fopen($filename, 'a+');
// then using this format
$fstring="||" . $date . "||" . $time . "||" . $name . "||" . $email . "||" . $website . "||" . $message . "
\r";
// write the comment
fwrite($fp, $fstring);
// reverse the comments
fputs ($fp, array_reverse ($fstring));
// close text file
fclose($fp);
The comments don’t reverse though! They still show the original way?
Thanks. x