使用包含HTML的行创建RSS提要会导致提要为空


Creating RSS Feed using rows containing HTML cause Feed to be blank

抱歉,如果这个问题之前已经问过了-有一个类似的标题的问题,但它不是我想要的。

我正在做的是从数据库中获取结果,并在适当的标签中打印出来,以创建RSS提要。

唯一的问题是文章的主体包含html标签,所以我的rss提要不能正确加载。

到目前为止,我已经试过了:

$rssfeed .= '<description>' . htmlentities($row['text') . '</description>';

$rssfeed .= '<description>' . htmlspecialchars($row['text'], ENT_COMPAT, 'UTF-8') . '</description>';

使用其中任何一个都只会给我一个完全空白的提要。

我实际上也试过这个,得到了相同的结果:

$rssfeed .= '<description>' . $row['text']. '</description>';

我现在更困惑了,肯定应该有工作吗?我唯一能想到的是,对于RSS提要来说,数据库中的行太长了,因为它是一篇完整的文章,里面有文本和HTML。

我不确定它是否会被自动截断。

任何想法?

这是一些示例输出:

<?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0">
        <channel>
            <title>RSS feed</title>
            <link>http://www.12345.co.uk</link>
            <description>RSS Feed from 12345.co.uk</description>
            <language>en-uk</language>
            <copyright>Copyright (C) 2011 12345.co.uk</copyright>
            <item>
                <title>Wear safe but stylish sunglasses on the slopes</title>
                <description><![CDATA["<p>Holidaymakers hitting the slopes this year must remember to pack a pair of sunglasses alongside their skis, one expert has highlighted.</p>
                <p>Dharmesh Patel, chairman of the Eyecare Trust, noted that UV protective eyewear is a must for skiers.</p>
                <p>Posted by xxxxx</p>v"]]>
                </description>
                <link></link>
                <pubDate>Mon, 03 Oct 2011 16:57:09 +0000</pubDate>
            </item>

由于RSS是一种xml语言,因此您需要使用CDATA部分:

<description><![CDATA["<b>Use tags here</b>"]]></description>

在PHP中,您可以通过使用startCData()endCData() -方法轻松地将其归档(与XMLWriter)。

XML-Reader是否正确显示HTML取决于它使用的解析器。但是,使用转义序列是有效的XML。

尝试strip_tags ($ row['文本']);http://php.net/manual/en/function.strip-tags.php

更新(i have all ok):
<?php echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
    <channel>
        <title>RSS feed</title>
        <link>http://www.12345.co.uk</link>
        <description>RSS Feed from 12345.co.uk</description>
        <language>en-uk</language>
        <copyright>Copyright (C) 2011 12345.co.uk</copyright>
        <item>
            <title>Wear safe but stylish sunglasses on the slopes</title>
            <description><![CDATA["<p>Holidaymakers hitting the slopes this year must remember to pack a pair of sunglasses alongside their skis, one expert has highlighted.</p>
            <p>Dharmesh Patel, chairman of the Eyecare Trust, noted that UV protective eyewear is a must for skiers.</p>
            <p>Posted by xxxxx</p>v"]]>
            </description>
            <link></link>
            <pubDate>Mon, 03 Oct 2011 16:57:09 +0000</pubDate>
        </item>

我不知道为什么,但它想显示代码结束它只是:</channel></rss>';?>