网址解析器错误:实体'nbsp'未定义

时间:2014-03-03 08:43:48

标签: php simplexml

我正在尝试使用simplexml_load_file()废弃bing图像搜索结果。我知道有一个API可以做到这一点,但这只是为了学习目的。

$xmlbingimage = simplexml_load_file('http://www.bing.com/images/search?q='.$bingimagequery.'&count=14&format=xml');

但它会像这样返回警告。

  

警告:simplexml_load_file():http://www.bing.com/images/search?q=mmm&count=14&format=xml:13:解析器错误:实体'nbsp'未在第159行的D:\ xampp \ htdocs \ images \ image.php中定义

我试图将file_get_contentshtml_entity_decodesimplexml_load_file()结合使用,但它会返回另一个错误:

代码:

$xmlbingimage = file_get_contents('http://www.bing.com/images/search?q='.$bingimagequery.'&count=14&format=xml');
$xmlbingimage = htmlentities($xmlbingimage);
$xmlbingimage = html_entity_decode($xmlbingimage, null, "UTF-8");
$xmlbingimage = simplexml_load_file($xmlbingimage);

错误:

  

警告:simplexml_load_file():I / O警告:无法加载外部实体“&lt;!DOCTYPE html PUBLIC” - // W3C // DTD XHTML 1.0 Transitional // EN“”http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang =“ en“xml:lang =”en“xmlns =”http://www.w3.org/1999/xhtml&quot; xmlns:Web =“http://schemas.live.com/Web/"><head><meta content =”text / html; charset = utf-8“http-equiv =”content-type“ /&gt;&lt; script type =“text / javascript”&gt; //&lt;![CDATA [si_ST = new Date //]]&gt;&lt; / script&gt;&lt; script type =“text / javascript”&gt; //&lt;![CDATA [sb_gh = function(){return location.hash},sb_sh = function(n){location.hash = n}; function _ge(n){return _d.getElementById(n)} _ w =窗口,_d = document,sb_de = _d.documentElement,sb_ie = !! _ w.ActiveXObject,sb_i6 = sb_ie&amp;&amp;!_ w.XMLHttpRe在D:\ xampp \ htdocs \ images \ image.php

为什么会返回这样的错误以及如何解决这个问题?

最好的问候

0 个答案:

没有答案
相关问题