|
I had the same error and fixed it by loading DOM first, then converting to SimpleXML. Instead of just loading the XML string directly to SimpleXML. Have no idea why SimpleXML errorer on loading the google custom search results xml string.
$this->xmlDoc = file_get_contents($this->url, 0, stream_context_create(array('http' => array('timeout' => 1))) );
if(!$this->xmlDoc) $this->error = "Could not get $url";
else
{
$dom = new DOMDocument;
$dom->loadXML($this->xmlDoc);
if (!$dom)
{
echo 'Error while parsing the document';
exit;
}
$this->xmlObj = simplexml_import_dom($dom);
/*
try {
$this->xmlObj = new SimpleXMLElement($this->xmlDoc);
}
catch (Exception $e)
{
$this->error = "SimpleXML did not work";
echo $this->error; exit;
}
*/
}
Error message before the fix was:
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: Entity: line 3: parser error : Premature end of data in tag GSP line 2 in googleCustomSearch.php on line 27
SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: <ERROR>500</ERROR>
PHP Warning: SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]:
|