Location: PHPKode > projects > HB-NS > hb-ns/write_xml.php
<?php
$filename = 'rss.xml';// the rss file
include_once("configuration.php");
include_once("functions.php");
$date = date("r");// Sat, 23 Oct 2004 00:13:26 +0200
// what timezone are you in (compared to GMT)?
$timezone = "+2000";

$somecontent = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";// hack for syntax coloring: <?php
$somecontent .= "<!-- feedurl: $news_base$filename -->\n";
$somecontent .= "<rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">
	<channel>
		<title>$sitename</title>
		<link>$base_url</link>
		<description>$description</description>
		<dc:language>en-us</dc:language>
		<dc:creator>$adminname</dc:creator>
		<dc:rights>$copy</dc:rights>
		<pubDate>$date</pubDate>
		<lastBuildDate>$date</lastBuildDate>
";

$query = "SELECT id, title, topic, text, DATE_FORMAT(publicationdate,'%a, %d %b %Y %T') as publicationdate FROM $table WHERE (expires >= '$now' OR expires = '00000000') AND push <= '$now'";
$query .= " ORDER BY id DESC LIMIT 0,10";
$result = mysql_query($query);

while($query_data = mysql_fetch_array($result))
{
	$article = $query_data["id"];
	$title = htmlentities($query_data["title"]);
	$topic = htmlentities($query_data["topic"]);
	$topic_name = urlencode($topic);
	$text = convertBBCode($query_data["text"]);
	$publicationdate = $query_data["publicationdate"];
	$publicationdate = $publicationdate . " " . "$timezone";// add timezone

	$somecontent .= "\t\t<item>\n";
	$somecontent .= "\t\t\t<title>$title</title>\n";
	$somecontent .= "\t\t\t<guid isPermaLink=\"true\">$news_base?article=$article</guid>\n";
	$somecontent .= "\t\t\t<link>$news_base?article=$article</link>\n";
	$somecontent .= "\t\t\t<description><![CDATA[$text]]></description>\n";
	$somecontent .= "\t\t\t<dc:subject>$topic</dc:subject>\n";
	$somecontent .= "\t\t\t<comments>$news_base?action=comment&amp;article=$article#comments</comments>\n";
	$somecontent .= "\t\t\t<pubDate>$publicationdate</pubDate>\n";
	$somecontent .= "\t\t</item>\n";
}

$somecontent .=	"</channel>\n";
$somecontent .="</rss>\n";
if (is_writable($filename))// check the rss file
{
	if (!$handle = fopen($filename, 'w'))// open the rss for overwriting
	{
		echo "<h4>Cannot open file $filename</h4>\n";
		exit;
	}
	if (fwrite($handle, $somecontent) === FALSE)// write the content
	{
		echo "<h4>Cannot write to file $filename</h4>\n";
		exit;
	}
	echo "<strong>$filename successfully written</strong>\n";
	fclose($handle);// close the rss file
}
else
{
	echo "<h4>The file $filename is not writable</h4>\n";// display error
}
?>
Return current item: HB-NS