O lord.. help me...

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

Post Reply
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

O lord.. help me...

Post by Jim »

I'm trying to write news to a file...

I'm trying to format the news using a template... here's the code to show you want I'm trying to do.

Code: Select all

$fp = fopen("/home/empirega/public_html/xg/news/xgn.txt","w");

	if($query) {
	
		while ($data = mysql_fetch_assoc($query)) {		
		
			  $subject = $data['subject'];
			  $author = $data['post_by'];
			  $body = $data['post_body'];
			  $date = date("l, F j Y \@ g:i a", $data['post_date']);
			  
			   
$news = "<? include('/home/empirega/public_html/xg/news/xgn_template.php'); ?>";
	

			
fputs($fp,$news,strlen($news));
fflush($fp);	

}

fclose($fp);

}
I understand PHP can't parse twice, or some such... If this is true, what can I use as an alternative? This is killing me. :P

Thanks!
hedge
Forum Contributor
Posts: 234
Joined: Fri Aug 30, 2002 10:19 am
Location: Calgary, AB, Canada

Post by hedge »

I think you need output buffering

http://ca2.php.net/manual/en/ref.outcontrol.php
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

You should really not save the template as .php, and instead, open it up, and use str_replace and preg_replace to put the information where it needs to be.

Or I guess you could just rename it to .txt, read the file into a string and try to work with http://www.php.net/eval
Post Reply