|
Posted by Andreas on 09/20/06 15:45
Here is the script that I used to generate RSS 2.0 feed using PHP.
<?php
$href="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$logo="http://www.embedworld.com/images/top_logo.gif";
$title="Embedworld download center";
$link="http://en.embedworld.com";
$copyright="Copyright (c) 2004-2006 Embedworld.com All Rights
Reserved.";
$language="en";
$title="Embedworld.com";
$description="Embedworld.com, Embedded unit the world!";
// Don't edit the content below
if(function_exists("getimagesize")) {
list($width, $height, $type, $attr) = getimagesize($logo);
} else {
list($width, $height)= array(88, 31);
}
$lastBuildDate=date("r");
if(1) {
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
header('Content-type: text/xml');
print "<?xml version=\"1.0\" encoding=\"gb2312\"?>";
print <<<HTML
<rss version="2.0">
<channel>
<title>$title</title>
<description>$description</description>
<copyright>$copyright</copyright>
<link>$link</link>
<language>$language</language>
<generator>Embedworld RSS Feed Generator 2.0</generator>
<lastBuildDate>$lastBuildDate</lastBuildDate>
<ttl>60</ttl>
<image>
<title>$title</title>
<width>$width</width>
<height>$height</height>
<link>$link</link>
<url>$logo</url>
</image>
HTML;
$dbtype="mysql";
include('./adodb471-1/adodb/adodb.inc.php');
if($dbtype == "mysql") {
$dbhost="localhost";
$dbname="test";
$dbport="3306";
$dbuser="root";
$dbpass="";
$dsn = "$dbtype://$dbuser:$dbpass@$dbhost/$dbname";
$db = NewADOConnection($dsn);
if (!$db) die("Connection failed");
}
if($dbtype == "access") {
//Access test here
$access="D:\\db_data.mdb";
$dbuser="";
$dbpass="";
$db =& ADONewConnection('access');
$dsn = "Driver={Microsoft Access Driver
(*.mdb)};Dbq=$access;Uid=$dbuser;Pwd=$dbpass;";
$db->Connect($dsn);
if (!$db) die("Connection failed");
}
///*
if(isset($query) && !empty($query)) {
$sql="select * from `db_class` where nsort ='down'";
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs = $db->Execute($sql);
if ($rs) {
while (!$rs->EOF) {
$data=$rs->GetAssoc();
foreach ($data as $i => $value) {
$sql2="select * from `db_sort` where id =$i";
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs2 = $db->Execute($sql2);
if ($rs2) {
while (!$rs2->EOF) {
$data2=$rs2->GetAssoc();
foreach ($data2 as $i2 => $value2) {
print <<<HTML
<item>
<title>ClassID: $i => $value </title>
<description> Sub ClassID: $i2 => $value2</description>
</item>
HTML;
}
$rs2->MoveNext();
}
}
}
$rs->MoveNext();
}
} else {
print "<error> Error <br /></error>\n";
} // End of else if ($rs)
unset($data, $sql, $i, $value);
print <<<HTML
</channel>
</rss>
HTML;
exit(0);
}
$cnt=0;
$sql="select * from `down` where $condition";
// print "<SQL> [$sql] </SQL>\n";
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
// $db->debug = true;
$rs = $db->Execute($sql);
if ($rs) {
$data=$rs->GetRows();
foreach ($data as $dt) {
print <<<HTML
<item>
<title>$name</title>
<link>$url</link>
<description>$remark</description>
<pubDate>$tim</pubDate>
</item>
HTML;
} // End of foreach
} else {
print "Error<br />\n";
}// End of else if ($rs)
print <<<HTML
</channel>
</rss>
HTML;
} // End ...
?>
Hopefully it is helpful to you!
Regards,
Signal
From: http://en.embedworld.com
Curtis.DanielN@gmail.com wrote:
> You will need to set the header :
> <?php
> header("Content-Type: text/xml");
> ?>
> the header has to be set in order to specify that you will be writing
> xml.
> When you want to print something like the ip do this:
> <ipaddress><?php echo $_SESSION["IPADDRESS"];?></ipaddress>
>
> After the header is set and you escape from php you'll just be creating
> regular xml tags and printing using php when you need to....I hope that
> helps
>
> Daniel
Navigation:
[Reply to this message]
|