好的,这是规格:
Dev Server:Windows,WAMP,PHP 5 +,Codeigniter
Live Server:Ubuntu Linux,PHP,CodeIgniter,LAMP
我在Live Server中从Firefox中收到以下错误:
XML解析错误:文档元素之后的垃圾 地点:http://www.mysite.com/feed/rss2/ 第2行,第1列:
语法错误,... rss2.php中的意外T_STRING
然而,在我的开发环境中,一切都像Windows中的漂亮一样。
任何人都可以帮助我吗?
以下是代码:
function rss2() {
@header("Content-Type: text/xml");
$settings = $this->db_model->get_db_settings();
$data['encoding'] = 'utf-8';
$data["feed_name"] = $settings["sitename"];
$data["feed_url"] = base_url() . "feed/rss2";
$data["page_description"] = "RSS Feed for " . $settings["sitename"];
$data["page_language"] = "en-us";
$data["creator_email"] = "noreply@noreply.com";
$data["todays_date"] = date("c");
//Array?
$rssfeed = $this->blog_model->get_blog_posts_by_status("published");
$i = 0;
foreach ($rssfeed as $row) {
//feed the details into the array
$rss_data[$i]["title"] = $row["title"];
$rss_data[$i]["permalink"] = base_url() . "content/blog/" . $row["slug"];
$rss_data[$i]["date"] = $row["date"];
$rss_data[$i]["description"] = utf8_encode(html_entity_decode($row["content"], ENT_QUOTES));
$rss_data[$i]["category"] = "No Category";
$i=1;
}
if ($i == 0) {
$data["rss_data"] = NULL;
} else {
$data["rss_data"] = $rss_data;
}
$this->load->view("system/feed/rss2", $data);
}
答案 0 :(得分:1)
听起来,XML声明开头的<?
被误识别为PHP代码块,然后PHP解释器就会窒息。
我似乎记得(虽然这可能是错误的)关闭short_open_tags
支持并不能解决这个问题。
解决方法是从PHP本身发出声明,如下所示:
<?php echo( '<?xml version="1.0" encoding="UTF-8"?>' ); ?>
答案 1 :(得分:0)
好的,如果这一切都错了,有人会帮助我。我修复了Live服务器上的问题,它在开发服务器上仍然可以。我唯一做的就是取出xml文档中的第一行:
<?xml version="1.0" encoding="UTF-8"?>
现在rss2.php文件如下所示:
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="<?php echo base_url() . 'feed/rss2/'; ?>" rel="self" type="application/rss+xml" />
<title><?php echo $feed_name; ?></title>
<link><?php echo $feed_url; ?></link>
<description><?php echo $page_description; ?></description>
<dc:language><?php echo $page_language; ?></dc:language>
<dc:creator><?php echo $creator_email; ?></dc:creator>
<dc:rights>Copyright <?php echo gmdate("Y", time()); ?></dc:rights>
<dc:date><?php echo $todays_date; ?></dc:date>
<admin:generatorAgent rdf:resource="http://www.codeigniter.com/" />
<?php if ($rss_data == null) { ?>
<item>
<title>We're Sorry. There is no data to view.</title>
<link><?php echo base_url(); ?></link>
<guid><?php echo base_url(); ?>#When:<?php echo $todays_date; ?></guid>
<description></description>
<dc:subject></dc:subject>
<dc:date><?php echo $todays_date; ?></dc:date>
</item>
<?php } else { ?>
<?php foreach($rss_data as $row) { ?>
<item>
<title><?php echo xml_convert($row['title']); ?></title>
<link><?php echo $row['permalink']; ?></link>
<guid><?php echo $row['permalink']; ?>#When:<?php echo $row['date']; ?></guid>
<description><?php echo xml_convert($row['description']); ?></description>
<dc:subject><?php echo xml_convert($row['category']); ?></dc:subject>
<dc:date><?php echo $row['date']; ?></dc:date>
</item>
<?php } } ?>
</channel>
</rss>
一切都像它应该的那样,但这是正确的吗?我不应该有那个编码行吗?让我知道。提前谢谢。