jackjames Posted March 31, 2011 Share Posted March 31, 2011 I'm pretty new to php. But the below script should get news articles from google news rss. It is failing to load the simplexml and returns false. Any idea why? $url = "http://news.google.com/news?geo=90210"; if ($xml = @simplexml_load_file($url)) { for ($i=0; $i<4; $i++) { $item= $xml->channel->item[$i]; $link= '<a href = "'.(string) $item->link.'", target= "_blank">'.(string) substr($item->title, 0, 50).'...</a><br />'; $news[]= $link; } } Link to comment https://forums.phpfreaks.com/topic/232299-simplexml-will-not-load/ Share on other sites More sharing options...
KevinM1 Posted March 31, 2011 Share Posted March 31, 2011 The '@' squelches errors. Remove it and see if simplexml_load_file() is actually generating an error. Link to comment https://forums.phpfreaks.com/topic/232299-simplexml-will-not-load/#findComment-1194990 Share on other sites More sharing options...
jackjames Posted March 31, 2011 Author Share Posted March 31, 2011 Thanks for your quick reply. When removed (@) I get many errors, below is an example of some of them. I've removed my home directory by line of code refers to: if ($xml = simplexml_load_file($url)) Warning: simplexml_load_file() [function.simplexml-load-file]: http://news.google.com/news?geo=02138:10: parser error : xmlParseEntityRef: no name in Warning: simplexml_load_file() [function.simplexml-load-file]: try{var pageT=null;GLOBAL_window.chrome&&GLOBAL_window.chrome.csi&&(pageT=Math.f in Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in Warning: simplexml_load_file() [function.simplexml-load-file]: http://news.google.com/news?geo=02138:10: parser error : EntityRef: expecting ';' in Link to comment https://forums.phpfreaks.com/topic/232299-simplexml-will-not-load/#findComment-1194999 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.