【问题标题】:Stripping   out of RSS feed with PHP使用 PHP 去除 RSS 提要
【发布时间】:2012-06-17 18:30:46
【问题描述】:

我有这个功能:

function validate($data) {
    $newData = str_replace(" ", " ", $newData);
    $newData = utf8_encode(htmlentities(strip_tags($data)));
    return $newData;
}

$rssfeed.='<description><![CDATA['.validate($news).']]></description>';

它从中提取的我的 MySQL 表使用 utf8-general_ci 编码。

但是,我的 XML 提要中仍然包含 &amp;nbsp;。任何想法为什么?

【问题讨论】:

  • 它实际上在 Chrome 的提要预览中显示 &nbsp;但在实际提要中用 &amp 显示。

标签: php xml encoding rss


【解决方案1】:

您以错误的顺序使用变量,因此您忽略了str_replace 的结果。

$newData = str_replace("&nbsp;", " ", $newData);
$newData = utf8_encode(htmlentities(strip_tags($data)));

应该是

$newData = str_replace("&nbsp;", " ", $data);
$newData = utf8_encode(htmlentities(strip_tags($newData)));

【讨论】:

  • 感谢我将其标记为正确答案,因为它已从提要中删除。 Google Reader 客户端仍然显示 &nbsp 很奇怪,但这可能只是浏览器问题,不确定。
【解决方案2】:

你的函数不应该是这样的吗:

function validate($data) { 
    $newData = str_replace("&nbsp;", " ", $data); 
    $newData = utf8_encode(htmlentities(strip_tags($newData))); 
    return $newData; 
} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 2012-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多