August 27, 2012 | In: Programovanie
google weather unsupported api – not available
Unsupported API – not available
seems that google api is out
google.com/ig/api?weather
if u dont, wrap simplexml_load_string in try/catch in php and use user error handling for xml:
try { $data = simplexml_load_string(...); catch( Exception $e ) { // error // do something with this $data }
real example:
... method ... $data = @file_get_contents($this->getApiUrl("", "Slovakia")); if(!$data) { return false; }; $data = iconv("ISO-8859-2", 'utf-8', $data); // enable user error handling libxml_use_internal_errors(true); // load the document $doc = new DOMDocument; if (!$doc->load($data)) { libxml_clear_errors(); return false; } try { $xmlData = new SimpleXMLElement($data); } catch (Exception $e) { return false; } return true; ... end method ...
or simple:
libxml_use_internal_errors(true); try{ $xmlObject = new SimpleXMLElement($wrongFormedText); } catch (Exception $e){ return false; }
1. always use error reporting 0!
2. do not dispaly ANY error on production!
2. wrap all your services for error handling
Comments are closed.