Benim site için bir RSS beslemesi oluşturmak için aşağıdaki komut dosyası kullanıyorum:
<?php
class RSS
{
public function RSS()
{
$root = $_SERVER['DOCUMENT_ROOT'];
require_once ("../connect.php");
}
public function GetFeed()
{
return $this->getDetails() . $this->getItems();
}
private function dbConnect()
{
DEFINE ('LINK', mysql_connect (DB_HOST, DB_USER, DB_PASSWORD));
}
private function getDetails()
{
$detailsTable = "rss_feed_details";
$this->dbConnect($detailsTable);
$query = "SELECT * FROM ". $detailsTable ." WHERE feed_category = ''";
$result = mysql_db_query (DB_NAME, $query, LINK);
while($row = mysql_fetch_array($result))
{
$details = '<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
<channel>
<title>'. $row['title'] .'</title>
<link>'. $row['link'] .'</link>
<description>'. $row['description'] .'</description>
<language>'. $row['language'] .'</language>
<image>
<title>'. $row['image_title'] .'</title>
<url>'. $row['image_url'] .'</url>
<link>'. $row['image_link'] .'</link>
<width>'. $row['image_width'] .'</width>
<height>'. $row['image_height'] .'</height>
</image>';
}
return $details;
}
private function getItems()
{
$itemsTable = "rss_posts";
$this->dbConnect($itemsTable);
$query = "SELECT * FROM ". $itemsTable ." ORDER BY id DESC";
$result = mysql_db_query (DB_NAME, $query, LINK);
$items = '';
while($row = mysql_fetch_array($result))
{
$items .= '<item>
<title>'. $row["title"] .'</title>
<link>'. $row["link"] .'</link>
<description><![CDATA['.$row["readable_date"]."<br /><br />".$row["description"]."<br /><br />".']]></description>
</item>';
}
$items .= '</channel>
</rss>';
return $items;
}
}
?>
Şaşırtıcı şey komut benim localhost üzerinde mükemmel çalışıyor ama benim uzak sunucuda aşağıdaki hatayı veriyor, bir:
XML Parsing Error: junk after document element
Location: http://mysite.com/rss/main/
Line Number 2, Column 1:<b>Parse error</b>: syntax error, unexpected T_STRING in <b>/home/studentw/public_html/rss/global-reach/rssClass.php</b> on line <b>1</b><br />
^