首页 > 解决方案 > simplexml_load_file():http://website.com/feed:563:解析器错误:未定义实体“nbsp”

问题描述

我正在尝试从网站加载 XML 数据,但出现以下错误:

simplexml_load_file(): http://website.com/feed:563: parser error : Entity 'nbsp' not defined
simplexml_load_file(): 00f0i\u00f0, vi\u00f0 h\u00f6fum m\u00f3tteki\u00f0 \u00fea\u00f0.\r\n\r\n 

这是代码:

$rss = simplexml_load_file('http://website.com/feed');
foreach ($rss->channel->item as $item) {
    $title = (string)trim(strip_tags($item->title));
    $title = html_entity_decode($post['title']);
    $description = (string)trim(strip_tags($item->description));
}

我无权编辑 XML 代码,那么如何解决这个问题?

更新:这是 RSS 提要的第一部分

<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:atom="http://www.w3.org/2005/Atom"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    >

<channel>
    <title></title>
    <atom:link href="" rel="self" type="application/rss+xml" />
    <link></link>
    <description></description>
    <lastBuildDate>Wed, 24 Feb 2021 12:12:53 +0000</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>
    hourly  </sy:updatePeriod>
    <sy:updateFrequency>
    1   </sy:updateFrequency>
    <generator></generator>

<image>
    <url></url>
    <title></title>
    <link></link>
    <width>32</width>
    <height>32</height>
</image> 
    <item>
        <title></title>
        <link></link>
        
        <dc:creator><![CDATA[]]></dc:creator>
        <pubDate>Wed, 24 Feb 2021 11:00:20 +0000</pubDate>
                <category><![CDATA[]]></category>
        <guid isPermaLink="false"></guid>

                    <description><![CDATA[ [...]]]></description>
                                        <content:encoded><![CDATA[<p></p>
<p></p>
<p><strong></strong></p>
<p> <a href=""></a></p>
]]></content:encoded>
</item>

如何使用 PHP 从这段代码中获取内容?

标签: phpxmlxml-parsingsimplexmlfeed

解决方案


推荐阅读