Hi peeps.
Okay. Be kind I am a complete beginner at PHP. No joke, started about 3 hours ago
Unfortunately, my first script was to be a 'news' form, to write to a file that I could include in a webpage.
Heartbroken, I was, when the PHP ate my file! Someone could have warned me that you can't write to the top of the file without zeroing it...
So I had a look about the Net, found a few examples, and botched together my script. But it dont work.
It seems to read the file, but I tried to have it input the file after my new 'input' and it just prints 'array'. Heres the code -
<?
if ($message) {
$message = ereg_replace("\r\n\r\n", "\n<P>", $message);
$date = date("l, F j Y, h:i a"
$message = "<B>$name </B> -- $date<P> $message <BR>";
$data = file(basename($PHP_SELF) . ".comment" // file you want insert line into
$c = count($data); // count existing lines
$fp = fopen(basename($PHP_SELF) . ".comment", 'w+'); // open the file for writing
fwrite($fp, $message);
for($i=0; $i<$c;$i++){
fwrite($fp, $data);
}
fclose($fp);
}
?>
Its a mess, I know, but I wasn't joking about doing this php thing for 3 hours.
I was wondering if I have missed something obvious?
Any comments/criticism/advice to give up now would be appreciated. Dean Owen
Okay. Be kind I am a complete beginner at PHP. No joke, started about 3 hours ago
Unfortunately, my first script was to be a 'news' form, to write to a file that I could include in a webpage.
Heartbroken, I was, when the PHP ate my file! Someone could have warned me that you can't write to the top of the file without zeroing it...
So I had a look about the Net, found a few examples, and botched together my script. But it dont work.
It seems to read the file, but I tried to have it input the file after my new 'input' and it just prints 'array'. Heres the code -
<?
if ($message) {
$message = ereg_replace("\r\n\r\n", "\n<P>", $message);
$date = date("l, F j Y, h:i a"
$message = "<B>$name </B> -- $date<P> $message <BR>";
$data = file(basename($PHP_SELF) . ".comment" // file you want insert line into
$c = count($data); // count existing lines
$fp = fopen(basename($PHP_SELF) . ".comment", 'w+'); // open the file for writing
fwrite($fp, $message);
for($i=0; $i<$c;$i++){
fwrite($fp, $data);
}
fclose($fp);
}
?>
Its a mess, I know, but I wasn't joking about doing this php thing for 3 hours.
I was wondering if I have missed something obvious?
Any comments/criticism/advice to give up now would be appreciated. Dean Owen