<![SimplePie中的CDATA [英] <![CDATA in SimplePie

查看:124
本文介绍了<![SimplePie中的CDATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一些RSS Scrapper,用于解析来自多个来源的数据.就是说,所有这些资源都有自己的RSS描述实现.

I've been working on some RSS Scrapper that parses data from multiple sources. That said, all this sources have their own implementation of the description of the RSS.

尤其是使用CDATA标记来写描述,例如

One in particular, uses CDATA tags to write the description on like, for example

<![CDATA[
<p align=justify><font face="verdana, arial, helvetica, sans-serif" size=1>
<font color=#004080></font>
SOME TEXT GOES HERE 
 </font></p>
]]>

但是,如果我尝试通过SimplePie获取商品说明,则会得到此输出

However if I try to get the item description with SimplePie I get this output

<div><p align="justify"></p></div>

我正在使用此php脚本来完成所有这些操作

I'm using this php script to do all this

 foreach($feed->get_Items() as $item)
 {

        $title = $item->get_title();
         $description = $item->get_description();
        //some other stuff
 }

现在好了

提要上的标题也是如此

<title>
  <![CDATA[ 
     Nice title
  ]]>
</title>

而且...有效!!

如何获取提要的描述?我已经尝试了几乎所有东西!

How can I get the description of the feed? I've tried almost everything!

谢谢!

推荐答案

get_description () get_content()方法都可以卫生,但是您可以使用

The get_description() and get_content() methods both do sanitation on the raw data, but you can use the get_item_tags() method to extract it untouched, like this:

$desc_tags = ($item->get_item_tags('', 'description')); // empty namespace is RSS2.0
if ($desc_tags) {
    print $desc_tags[0]['data'];
}

唯一的警告是,当get_contentget_description将尝试检测名称空间时,您必须将其提供给get_item_tags,您可以看到

The only caveat is while the get_content or get_description will try to detect the namespace, you will have to provide it to get_item_tags, you can see the namespace constants here. If you know the feeds format beforehand that should not be a problem, otherwise you might need to do the trial and error that the get_description do.

这篇关于&lt;![SimplePie中的CDATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆