Write to the top of a flat file

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!

Moderator: General Moderators

User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

Yes line 19 is:

Code: Select all

fwrite($fp, join('',$oldnews);
Spot the deliberate mistake lol.... Always do this... yup I'v missed of a bracket:

Code: Select all

fwrite($fp, join('',$oldnews));
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

it's printing Array to the text file after every news entry
mathewvp
Forum Commoner
Posts: 28
Joined: Wed Apr 23, 2003 10:28 am

Post by mathewvp »

Try this

Code: Select all

<?php 
if((!isset($_POST&#1111;'subject'])) or (!isset($_POST&#1111;'news']))) 
&#123; 
     echo 'You must enter <b>ALL</b> fields before you can continue!'; 
     exit; 
&#125; 
$subject = $_POST&#1111;'subject']; 
$news = $_POST&#1111;'news']; 
$time = date("D d of F, h:i a"); 

$oldnews = implode('',file("news.txt"));

$fp = fopen("news.txt", "w"); 
$insertcode = "<table width='100%' border='0' cellspacing='1' cellpadding='2' bgcolor='#dcdcdc' align='center'><tr><td width='100%' border='1' bgcolor='whitesmoke'>".$subject." - ".$time."</td></tr><tr><td width='100%' border='1' bgcolor='#ffffff'>".$news."</td></tr></table><br>"; 


fwrite($fp, $insertcode); 
fwrite($fp,$oldnews); 
fclose($fp); 
?>
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

thanks man, i love this place, it works perfectly
Post Reply