php - Chrome 上文档末尾的额外内容

标签 php mysql xml

http://seosailor.com/beta2/articles/showrss此网址在 chrome 上出现错误 Extra content at the end of the document

我的代码是这样的

function showrss() {
    header("Content-Type: application/xml; charset=ISO-8859-1");
     $query_items = "select * from articles";   
    $result_items  = mysql_query ($query_items) or die("Some error: ".mysql_error());                             
    $xml = '<?xml version="1.0" encoding="ISO-8859-1" ?><rss version="2.0"><channel>';
    while($row = mysql_fetch_array($result_items))
        { 
            //$des = mysql_real_escape_string($row['a_description']);
        //  $a_des = str_replace(']]>', ']]&gt;',$row['a_description']);
            //$a_des = strip_tags($row['a_description']);
        //  $a_des = preg_replace('/[^a-zA-Z0-9\s]/', '', strip_tags($row['a_description']));
            $a_des = htmlspecialchars($row['a_description']);
        $xml .= '<item>
         <title>'.$row["a_title"].'</title>
         <link>'.$row["a_url"].'</link>
         <description>'.$a_des.'</description></item>';
        }   $xml .= '</channel>';
             $xml .= '</rss></xml>';
            echo $xml;}

最佳答案

那是因为额外的</xml>结束标记位于末尾(没有开始 <xml> 标记)。

关于php - Chrome 上文档末尾的额外内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18766642/

相关文章:

xml - Erlang xml 到元组和列表

php - 在 Windows 中为 MySQL 配置 ODBC

php - 为什么 Laravel 5 移除了 Cascading Configs

php - 正则表达式,PHP-从复杂的 json 字符串中删除单引号、双引号和反斜杠

插入文件时,MySQL 查询速度变慢

xml - 如何处理 XPath 2.0 表达式除以零的错误

java - 为什么元素创建需要 DOM 中的文档对象?

php - SQLSTATE[HY000] [1045] 用户 'landon_app' @'localhost' 的访问被拒绝

php - 如何使用php将数据数组插入mysql

mysql - 为什么我的 ORDER BY BIGINT(20) 需要这么长时间?