1

I am getting the below error when parsing google weather. Anyone know a solution for this been looking everywhere but no joy

Entity: line 2: parser error : AttValue: " or ' expected

    $lang ='English';
    $place=urlencode($weather);
    $place = utf8_encode($place);
    $url = 'http://www.google.com/ig/api?weather='.$place.',$&hl='.$lang.'';        

    $ch = curl_init();       
    //Set CURL options
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
    $raw_data = curl_exec($ch);
    //close CURL cause we dont need it anymore
    curl_close($ch);         

    $xml = simplexml_load_string($raw_data);
Spudley
  • 166,037
  • 39
  • 233
  • 307
Matthew Chambers
  • 869
  • 3
  • 20
  • 34

1 Answers1

2

The google weather API is known to throw 403 errors from time to time. When that happens, the request will be answered with an HTTP 403 response and an HTML error document. Since the error document is not valid XML, you cannot parse it with simplexml_load_string.

You should use another weather API.

Community
  • 1
  • 1
phihag
  • 278,196
  • 72
  • 453
  • 469
  • why have they been disabled. If you click the link you can see there is data available. – Matthew Chambers Aug 18 '12 at 10:13
  • it was working fine about a month ago- i still get data back from the link you provided – Matthew Chambers Aug 18 '12 at 10:18
  • @MatthewChambers Oh, you're right. It hasn't been disabled (I thought it would be one of the [ones deprecated in 2012](http://googledevelopers.blogspot.de/2012/04/changes-to-deprecation-policies-and-api.html)). It just returns 403 errors from time to time. Currently, I get a consistent 403 from three different IPs. – phihag Aug 18 '12 at 10:24