Forum Moderators: coopster
$xml = new SimpleXMLElement(file_get_contents("http://www.weatherexample.com/london.rss"));
$today = $xml->channel->item[0]->description['value'];
$url = "http://www.weatherexample.com/london.rss";
$xml = simpleXML_load_file($url,"SimpleXMLElement",LIBXML_NOCDATA);
$today = $xml->channel->item[0]->description;
$xml_err=null;
$url='http://feed.example.com/?key='.DEV_KEY.'&keyword="'.$keyword.'";
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$o=curl_exec($ch);
// Error trapping = best friend
// these are recorded in my function "record_results"
// instead of the error log
libxml_use_internal_errors(true);
$a=simplexml_load_string($o);
//
if (!$a) {
$xml = explode("\n", $o);
$errors = libxml_get_errors();
foreach ($errors as $error) {
$xml_err .= display_xml_error($error, $xml);
}
record_results("XML ERROR: $keyword",$xml_err);
libxml_clear_errors();
}
else {
if ($a->item) { // only if there's "item" in the tree
foreach ($a->item as $v){
$result[]=$v; // array of parsed results
}
}
}
function display_xml_error($error, $xml) {
$return = $xml[$error->line - 1] . "\n";
$return .= str_repeat('-', $error->column) . "^\n";
switch ($error->level) {
case LIBXML_ERR_WARNING:
$return .= "Warning $error->code: ";
break;
case LIBXML_ERR_ERROR:
$return .= "Error $error->code: ";
break;
case LIBXML_ERR_FATAL:
$return .= "Fatal Error $error->code: ";
break;
}
$return .= trim($error->message) .
"\n Line: $error->line" .
"\n Column: $error->column";
if ($error->file) {
$return .= "\n File: $error->file";
}
return "$return\n\n--------------------------------------------\n\n";
}