Welcome Guest, Not a member yet? Register   Sign In
SimpleXMLElement
#1

[eluser]a.somervell[/eluser]
'nother question for the group:

Code:
$url = "http://maps.google.com/maps/geo?output=xml&key=ABQIAAAAnbn99sEqA=".str_replace(" ","+", preg_replace("/[^a-zA-Z0-9 ]/", "", preg_replace('/\s\s+/'," ", $address)));

try {
  $kml = new SimpleXMLElement( file_get_contents($url, "r"));
} catch (Exception $e) {
  //Do something exceptional...
}

If $address is say... "143" then the google XML will come back with a ridiculously long number of addresses, not idea but thats fine, I just go "found more than one address, please be more specific" to the user.

Problem is all the Japanese, Czech and other weird characters that come through that makes SimpleXMLElement go:

Code:
SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xFD 0x3C 0x2F 0x41

I figure I have to run the response through some sort of character translation function between getting the contents and passing it to SimpleXMLElement... But I cant figure out what that should be...?
#2

[eluser]a.somervell[/eluser]
Gah, found a fix, my google foo seemed to get stronger after asking "the group" haha:
http://groups.google.com/group/Google-Ma...550ad051d9
#3

[eluser]GSV Sleeper Service[/eluser]
is that your google API Key? you may want to edit that out..
#4

[eluser]a.somervell[/eluser]
weeell... Dev key hence not caring but I've cut it since ya commented :p




Theme © iAndrew 2016 - Forum software by © MyBB