
May 25th, 2006, 05:28 PM
|
|
Contributing User
|
|
Join Date: May 2006
Location: CO, USA
Posts: 34
Time spent in forums: 11 h 39 m 23 sec
Reputation Power: 3
|
|
|
RSS error!
Hi,
Today, I wrote a RSS script for my CMS. When I browse it in my internet exploer, I got the following error:
Quote: The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
A semi colon character was expected. Error processing resource 'http://www.yipaihuyan.com/rss/rss.php'. Line 11, Position ...
<link>e/public/InfoUrl?classid=3&id=14024</link>
-----------------------------------^
|
And here's the php script for rss.php:
PHP Code:
<?php
error_reporting(7);
require_once("config.php");
require_once("class/mysql.php");
$title="website name";
$showNum = 20;
$length=300;
//initialize mysql database
$DB = new MySql;
$DB->dbconnect($hostname, $dbuser, $dbuserpass,$dbname);
unset($hostname, $dbuser, $dbuserpass);
//get url
function GetURL()
{
$path = $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
Return $path;
}
//get char
function Substring($strings,$start,$length) {
global $length;
$str = substr($strings, $start, $length);
$char = 0;
for($i = 0; $i < strlen($str); $i++) {
if (ord($str[$i]) > 128)
$char++;
}
$str2 = substr($strings, $start, $length+1);
if ($char%2 == 1){
if ($length <= strlen($strings)) {
$str2 = $str2 .= "...";
}
return $str2;
}
if ($char%2 == 0) {
if ($length <= strlen($strings)) {
$str = $str .= "...";
}
return $str;
}
}
//retrieve lastest 20 articles
function GetNew()
{
global $db_prefix,$DB,$showNum;
$sql = "SELECT * FROM `".$db_prefix."ecms_news` ORDER BY `id` DESC LIMIT 0, ".$showNum;
$result = $DB->query($sql);
$i = 0;
while($re = $DB->fetch_array($result))
{
$rss[$i]['id'] = $re['id'];//article ID
$rss[$i]['title'] = $re['title'];//article title
$rss[$i]['date'] = $re['newstime'];//publish time
$rss[$i]['content'] = Substring($re['newstext'],0,$length);//article summary $re['smalltext'];
$rss[$i]['writer'] = $re['writer'];
$rss[$i]['titleurl'] ="e/public/InfoUrl?classid=".$re['classid']."&id=".$re['id'];//display class ID
$i++;
}
return $rss;
}
//number of items
function GetRssNum()
{
$RssNum = GetNew();
return count($RssNum);
}
//display
$URL = GetURL();
$GetNew = GetNew();
$RssNum = GetRssNum();
header("Content-type:application/xml");
print <<< END
<?xml version="1.0" encoding="gb2312" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns="http://my.netscape.com/rdf/simple/0.9/">
<channel>
<title>$title</title>
<link>http://$URL</link>
<description>$title website title</description>
<dc:language>zh-cn</dc:language>
</channel>
END; for($i = 0;$i<$RssNum;$i++)
{
$a[1] = $GetNew[$i]['id'];
$a[2] = $GetNew[$i]['title'];
$a[3] = $GetNew[$i]['date'];
$a[4] = $GetNew[$i]['classid'];
$a[5] = $GetNew[$i]['content'];
$a[6] = $GetNew[$i]['writer'];
$a[7] = $GetNew[$i]['titleurl'];
print <<< END
<item rdf:about="$a[6]">
<title>$a[2]</title>
<link>$a[7]</link>
<description><![CDATA[ $a[5]]]></description>
<dc:date>$a[3]</dc:date>
<author>$a[6]</author>
</item>
END; }
print <<< END
</rdf:RDF>
END; ?>
anythign wrong? how to correct this error?
thanks
|