第9行第1行的错误:仅在文档开头允许XML声明

时间:2017-04-19 01:37:07

标签: php xml

我正在尝试构建一个XML文件。但坚持错误。我包括代码和错误。提前谢谢。

<?php 
_setView(__FILE__);
_setLayout('rss');

header('Content-type: application/xml; charset="utf-8"',true);

mb_internal_encoding("UTF-8");

    $name = ''; 
    $link = '';
    $whereQuery = '';
    if(isset($_GET['category'])) {
        $whereQuery .= " AND `categories` LIKE '%,".intval($_GET['category']).",%' ";

        $categoriesClass = new categories();

        $category = $categoriesClass->get($_GET['category']);

        $name = $category['name'];
        $link = '?category='.$_GET['category'];
    }
    if(isset($_GET['user'])) {
        $whereQuery .= " AND `user_id` = '".intval($_GET['user'])."' ";

        $usersClass = new users();

        $user = $usersClass->get($_GET['user']);

        $name = $user['username'];
        if($link == '') {
            $link = '?user='.$_GET['user'];
        }
        else {
            $link .= '&user='.$_GET['user'];
        }   
    }

echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<rss version=\"2.0\">
<channel>
<title>".$config['domain']." - ".$name." RSS</title>
<link>http://".$config['domain']."/rss/".$link."</link>
<description></description>
";

#LOAD RECIPES   
    $itemsClass = new items();

    $rows = $itemsClass->getAll(0, 20, " `status` = 'active' ".$whereQuery, "`datetime` DESC");
    if(is_array($rows)) {
        foreach($rows as $r) {
            echo "
                <item>
                    <title><![CDATA[ ".$r['name']." ]]></title>
                    <link>http://".$config['domain']."/".$languageURL."items/".$r['id']."</link>
                    <description><![CDATA[
            ";

            if($r['thumbnail'] != '') {
                echo "<a href=\"http://".$config['domain']."/".$languageURL."items/".$r['id']."\"><img src=\"".$config['data_server']."/uploads/items/".$r['id']."/".$r['thumbnail']."\" alt=\"\" border=\"0\" style=\"float:left; margin:0 10px 0 0;\" /></a>";
            }

            echo "<br />".mb_substr(strip_tags($r['description']), 0, 200)."";

            echo "]]></description>
                 <guid>http://".$config['domain']."/".$languageURL."items/".$r['id']."</guid>                 
              </item>
            ";
        }
    }

echo "
</channel>
</rss>
";      

?>

显示以下错误

  

此页面包含以下错误:

     第9行第1行的

错误:仅在开始时允许XML声明   该文档的下面是第一个页面的渲染   错误。

0 个答案:

没有答案