Page 1 of 1

O lord.. help me...

Posted: Wed Mar 05, 2003 3:56 pm
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!

Posted: Wed Mar 05, 2003 4:59 pm
by hedge
I think you need output buffering

http://ca2.php.net/manual/en/ref.outcontrol.php

Posted: Wed Mar 05, 2003 10:49 pm
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