Reputation: 3
I've been writing a simple PHP script which is supposed to generate a RSS Feed extracting data from a MySQL database.
<?php
require("$_SERVER[DOCUMENT_ROOT]mysql.php");
$type = $_GET["type"];
$result = mysql_query("SELECT * FROM Setting WHERE Type = \"$type\"");
header("Content-Type: text/xml");
echo "
<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
<rss version=\"2.0\">
<channel>
<title>Vhannibal – I migliori setting per Dreambox! – Feed RSS</title>
<link>http://www.vhannibal.net/</link>
<description>".$type."</description>
";
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "
<item>
<title>$row[Name]</title>
<link>http://www.vhannibal.net/download_setting.php?id=$row[ID]</link>
<description>".strftime("%e %b", $row["Date"])."</description>
</item>
</channel>
</rss>
";
}
?>
The problem is <?xml version="1.0" encoding="iso-8859-1"?>
comes after an unwanted empty line generated by the PHP script which I think is the reason why it doesn't work. Am I right? How can I solve it? Thanks.
Upvotes: 0
Views: 2083
Reputation: 19194
Your problem is the –
entity in the title element which is not valid in xml (it's an html defined entity); just use "-" or use the decimal version: ‒
.
Also, you need to put the channel
and rss
end tags outside of the while cycle.
To get rid of the first blank line, just replace
echo "
<?xml version="1.0" encoding="iso-8859-1"?>
[...]
with
echo "<?xml version="1.0" encoding="iso-8859-1"?>
[...]
Upvotes: 2