PHP:RSS 提要无法验证是否存在重音字符

PHP: RSS feed does not validate with accented characters present

我用 php 制作了自己的 rss 提要,但是当我使用重音字符时无法验证它。我找不到解决方案。

到目前为止,这是我的 RSS 提要:

<?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' 编解码器无法解码位置 2474 中的字节 0xe9:无效的连续字节(可能是 high-bit 字符?)”

然后我检查了我的 Firefox 和 IE 浏览器,它只是不显示带有重音字符的项目。整个提要中的其他项目显示得很好。

这是 header 信息:

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

我自己找到了答案。

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

示例:

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

echo $title