0
我使用笨庫和我使用下面的代碼來生成XML RSS饋送文件 這是控制器的代碼: 得到在Rss.xml不想要的數據文件
class Rssfeed extends MY_Controller {
public function Generate_rss_feed()
{
$this->load->helper('visitors');
$data['visitors'] = visitors_counter($this,$this->input->ip_address());
$this->load->helper('xml');
$this->load->helper('text');
$this->load->model('news_model');
$data['feed_name'] = 'MyWebsite.com'; // your website
$data['encoding'] = 'utf-8'; // the encoding
$data['feed_url'] = base_url().'index.php/rssfeed/Generate_rss_feed'; // the url to your feed
$data['page_description'] = '';//some description
$data['page_language'] = 'ar-ar'; // the language
$data['posts'] = $this->news_model->get_latest_news(3);
header("Content-Type: application/rss+xml"); // important!
$data['mode']= 'rss_feed';
$data['view_page']= 'rss';
$this->load->view('rss', $data);
}
}
並在視圖那裏分別是:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<?php
$rss_feed = '<?xml version="1.0" encoding="' . $encoding . '"?-->' . "\n".'
<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<channel>
<title>'.$feed_name.'</title>
<link>'.$feed_url.'
<description>'. $page_description.'</description>
<dc:language>'. $page_language.'</dc:language>
<dc:rights>Copyright'. gmdate("Y", time()).'</dc:rights>
<admin:generatoragent rdf:resource="http://www.codeigniter.com/">';
foreach($posts as $post){
$rss_feed .='<item>
<title>'.xml_convert($post->Title).'</title>
<link>'.site_url('blog/posting/' . $post->ID).'</link>
<guid>'. site_url('blog/posting/' . $post->ID).'</guid>
<description>'.$post->Head_line .'</description>
<pubdate>'.date("F j, Y, g:i a",$post->Date).'</pubdate>
</item>';
}
$rss_feed .= ' </admin:generatoragent></channel>
</rss>';
force_download('feed.xml', $rss_feed);
?>
</body>
</html>
的問題是,當我下載的XML文件,它包含:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
我不知道它來自哪裏?任何幫助..
不在視圖代碼的頂部你只是貼? –
是的,但我強制文件中的輸出數據是變量的內容$ rss_feed –
然後,只需刪除「外部代碼」,在PHP之外......所以它應該只是 – fedmich