URL parser error : Entity 'nbsp' not defined

I am trying to scrap bing image search result using simplexml_load_file() . I know there is an API to do that, but this is for learning purpose only.

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

But it is return Warning like this.

Warning: simplexml_load_file(): http://www.bing.com/images/search?q=mmm&count=14&format=xml:13: parser error : Entity 'nbsp' not defined in D:xampphtdocsimagesimage.php on line 159

I have trying to use file_get_contents and html_entity_decode to be combined with simplexml_load_file() but it's returning another error:

Code:

$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);

Error:

Warning: simplexml_load_file(): I/O warning : failed to load external entity "<!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" /><script type="text/javascript">//<![CDATA[ si_ST=new Date //]]></script><script type="text/javascript">//<![CDATA[ sb_gh=function(){return location.hash},sb_sh=function(n){location.hash=n};function _ge(n){return _d.getElementById(n)}_w=window,_d=document,sb_de=_d.documentElement,sb_ie=!!_w.ActiveXObject,sb_i6=sb_ie&&!_w.XMLHttpRe in D:xampphtdocsimagesimage.php

Why it is returning errors like that and how to resolve that problem?

Best Regards

链接地址: http://www.djcxy.com/p/69692.html

上一篇: PHP CURL检索部分页面

下一篇: URL解析器错误:实体'nbsp'未定义