首页 文章

PHP:RSS提要不会使用重音字符进行验证

提问于
浏览
2

我使用php创建了自己的RSS源,但是当我使用重音字符时,我无法验证它 . 我无法找到解决方案 .

这是我的RSS feed直到现在:

<?xml version="1.0"?>
        <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
        <channel>
        <title>My site</title>
        <link>http://www.example.com</link>
        <description>The newest music</description>
        <atom:link href="http://www.example.com/feed.php" rel="self"></atom:link>
        <item>
        <title><![CDATA[Beyoncé - Sorry]]></title>
        <description>New Music</description>
        <pubDate>Thu, 23 Jun 2016 09:07:10 +0000</pubDate>
        <guid>http://www.example.com/beyonce/sorry</guid>
        <enclosure url="mypicture.jpg" length="0" type="image/jpeg"></enclosure>
        <link>http://www.example.com/beyonce/sorry</link>
        </item>
        </channel>
    </rss>

我尝试了CDATA标签,它修复了特殊字符,但没有重音 . 有什么想法吗?

我使用:https://validator.w3.org/feed/check.cgi作为验证器 . 错误消息:"'utf8' codec can't decode byte 0xe9 in position 2474: invalid continuation byte (maybe a high-bit character?)"

我检查我的Firefox和IE浏览器,它只是没有显示带有重音字符的项目 . 整个Feed中的其他项目显示得很好 .

这是 Headers 信息:

header('Content-type: text/xml; charset=utf-8');

1 回答

  • 0

    我自己找到了答案 .

    确保使用utf8_encode()来获得正确的重音字符 .

    例:

    $title = Beyoncé;
    $title = utf8_encode($title);
    
    echo $title
    

相关问题