dops57958 2015-10-20 03:25 采纳率: 0%
浏览 35

RSS中的两个CDATA选择

my RSS create by PHP and this is my code

<?php
include('dataservice.php');
include('data/article.php');
include('bussiness/article.php');
function sumary($string,$len)
{
 if($len > strlen($string)){$len=strlen($string);};
$pos = strpos($string, ' ', $len);
if($pos){$string = substr($string,0,$pos);}else{$string = substr($string,0,$len);}    
return $string." ...";
}
$article = new articlebs();
$data_article = $article->Getdata(); 
$Sum = $data_article == false ? 0 : count($data_article);
if($Sum!= 0)
{
    header('Content-Type: text/xml; charset=utf-8'."
");

    echo ('<rss xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">'."
");
    echo ('<channel>'."
"); 
    echo('<title>Test</title>'."
");
    echo('<link>http://localhost</link>'."
");
    echo('<description>Test RSS</description>'."
");

    for($i = 0; $i < $Sum; $i++)
    {
        $Id_Article = $data_article[$i]['Id_Article'];
        $Title   = $data_article[$i]['Title'];
        $Content   = $data_article[$i]['Content'];
        $Time   = $data_article[$i]['Time'];
        $Id_User   = $data_article[$i]['Id_User'];

        preg_match('/<img.+src=[\'"](?P<src>.+)[\'"].*>/i', $Content, $image);

        $image = preg_replace( '/(width|height)="\d*"\s/', "", $image );
        $image = preg_replace( '/"/', "", $image );
        $image = preg_replace( '/height=\d*/', "", $image );
        $image = preg_replace( '/(width|height)=\d*/', "", $image );

        echo('<item>'."
");

        echo ('<title>').$Title.('</title>'."
");
        if( empty( $image ) )
        {
            echo  ('<image>http://localhost/images/noimg.jpg</image>'."
");
        }
        else
        {
            echo ('<image>'). $image['src'].('</image>'."
");
        }  
        echo ('<link><![CDATA[')."http://localhost/index.php?detail&id=".$Id_Article.(']]></link>'."
");
        echo ('<pubDate>').$Time.('</pubDate>'."
"); 
        echo ('<guid><![CDATA[').$Content.(']]></guid>'."
"); 
        echo ('<description><![CDATA[');
        echo strip_tags(sumary($Content,500));
        echo (']]></description>'."
");
        echo ('<content:encoded> <![CDATA['.$Content.']]> </content:encoded>'); 
        echo ('</item>'."
");

    }
    echo ('</channel>'."
");
    echo ('</rss>');
}
?>

This code run normaly, but it's appearing some wrong. I see my content include two CDATA selection like this:

Two cdata

I try to google it but not result, please help me to fix it. Thank you so much.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题