Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On a similar subject.... 1

Status
Not open for further replies.

QuietDean

Instructor
Mar 10, 2001
163
GB
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(&quot;\r\n\r\n&quot;, &quot;\n<P>&quot;, $message);

$date = date(&quot;l, F j Y, h:i a&quot;);
$message = &quot;<B>$name </B> -- $date<P> $message <BR>&quot;;

$data = file(basename($PHP_SELF) . &quot;.comment&quot;); // file you want insert line into
$c = count($data); // count existing lines
$fp = fopen(basename($PHP_SELF) . &quot;.comment&quot;, '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
 
Try replacing the for loop with this

for($i=0; $i<$c;$i++){
fwrite($fp, $data[$i]);
}

That should fix the &quot;array&quot; output problem.
 
Ohhhh, your good. My only regret now is that I can only give you one star.....

:)

Thanks! Dean Owen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top