redhead
12-28-2002, 10:08 PM
hmmm... i seem to be asking alot more questions in this particular forum than i'm answering, i guess its all helping me improve. i think this is another of them problems that is gonna seem so simple when i see the correct answer...
ok... i'll tell you everything so i dont miss everything out (could end up very long:o) im trying to create a guestbook, and with mySQL not being supported on my host i am forced to use flat text databases.
To give you an idea of what im doing, here's the code ive already written that the form posts to:<?php
$name = strip_tags($HTTP_POST_VARS["name"]);
$name = str_replace('/"','"',$name); // not sure about that bit
$message = strip_tags($HTTP_POST_VARS["comment"]);
$message = nl2br($message);
$code = "<div style=\"background-color: #C18240; padding-left: 2px;\">\nPosted by <b>";
$code .= $name."</b> on <b>".date('d/m/y, h:ia')."</b></div>".$message."<br><br>";
// write into the posts file
$fp = fopen("guestbook.spud","r+");
fwrite($fp, $code);
fclose($fp);
header('Location: interact.php');
?>it works... but i was using r+ in the fopen() function so that it would save at the beginning of the text file, (so when the text file is included in the page the latest post will be at the top). but r+ didnt do what i had expected it to do, it overwrites what is already there from the beginning, rather than inserting the new code before the contents of the message.
so, (eee... this is very long winded, sorry!) I was going to add the existing contents of the file to the $code variable, so the rest of the guestbook would remain intact after the new message. i used file('guestbook.spud') to add this, but it made it an array which doesnt save properly in the file...
how do I add the existing contents of a file to a variable?
thanks,
ok... i'll tell you everything so i dont miss everything out (could end up very long:o) im trying to create a guestbook, and with mySQL not being supported on my host i am forced to use flat text databases.
To give you an idea of what im doing, here's the code ive already written that the form posts to:<?php
$name = strip_tags($HTTP_POST_VARS["name"]);
$name = str_replace('/"','"',$name); // not sure about that bit
$message = strip_tags($HTTP_POST_VARS["comment"]);
$message = nl2br($message);
$code = "<div style=\"background-color: #C18240; padding-left: 2px;\">\nPosted by <b>";
$code .= $name."</b> on <b>".date('d/m/y, h:ia')."</b></div>".$message."<br><br>";
// write into the posts file
$fp = fopen("guestbook.spud","r+");
fwrite($fp, $code);
fclose($fp);
header('Location: interact.php');
?>it works... but i was using r+ in the fopen() function so that it would save at the beginning of the text file, (so when the text file is included in the page the latest post will be at the top). but r+ didnt do what i had expected it to do, it overwrites what is already there from the beginning, rather than inserting the new code before the contents of the message.
so, (eee... this is very long winded, sorry!) I was going to add the existing contents of the file to the $code variable, so the rest of the guestbook would remain intact after the new message. i used file('guestbook.spud') to add this, but it made it an array which doesnt save properly in the file...
how do I add the existing contents of a file to a variable?
thanks,