Reputation: 3949
Trying to make this peace of code work. But I get the Fatal error. I am not sure how to fix this. Any help would be appreciate it. The error is for this line: $counts = $sxml-> children('http://a9.com/-/spec/opensearchrss/1.0/');
// generate feed URL
$feedURL = "http://gdata.youtube.com/feeds/api/videos/-/{$q}
?orderby=viewCount&max-results={$i}";
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
// get summary counts from opensearch: namespace
$counts = $sxml-> children('http://a9.com/-/spec/opensearchrss/1.0/');
//$counts = $sxml-> children('http://www.opensearch.org/Specifications/OpenSearch/1.1');
$total = $counts->totalResults;
$startOffset = $counts->startIndex;
$endOffset = ($startOffset-1) + $counts->itemsPerPage;
Upvotes: 1
Views: 16827
Reputation: 91
To avoid getting this error, you should use condition like:
if(false !== $sxml){
//your code
}
Upvotes: 1
Reputation: 64526
simplexml_load_file
has failed. It returns false (a none object) on failure.
Either your server can't access the URL, or it is returning invalid XML.
From the Manual:
Returns an object of class SimpleXMLElement with properties containing the data held within the XML document, or FALSE on failure.
Upvotes: 3