singlephile Posted May 3, 2007 Share Posted May 3, 2007 I've added a google map to my site and when a user registers it asks for their address which it then geocodes and adds to the map (eg finds the latitude and longitude). Now normally this is in the US and i don't have a problem, but now and again i'll have someone register from, say, germany and the xml returned by google contains foreign characters and the parsing crashes and gives and "Invalid character" error. Here's an example of the xml: http://maps.google.com/maps/geo?q=Marktstr,M%F6nchengladbach,Germany&output=xml&key=ABQIAAAABF49M8jz0TUmr8jXDZwxsRS8-uVPCF0YzVBqSr0MDYVbXh-zfhT27vCkbr5-6YvIIf7aVUFJNXewFw Any ideas out there? Link to comment https://forums.phpfreaks.com/topic/49889-xml-parse-invalid-character-error/ Share on other sites More sharing options...
corbin Posted May 3, 2007 Share Posted May 3, 2007 The xml file looks correct so it has to have something to do with the php script handling it, or the client side stuff.... Link to comment https://forums.phpfreaks.com/topic/49889-xml-parse-invalid-character-error/#findComment-244733 Share on other sites More sharing options...
singlephile Posted May 3, 2007 Author Share Posted May 3, 2007 Here's the code i use to parse: if (! ($xmlparser = xml_parser_create()) ) { die ("Cannot create parser"); } xml_set_element_handler($xmlparser, "start_tag", "end_tag"); xml_set_character_data_handler($xmlparser, "tag_contents"); $filename = 'http://maps.google.com/maps/geo?q=Marktstr,M%F6nchengladbach,Germany&output=xml&key=ABQIAAAABF49M8jz0TUmr8jXDZwxsRS8-uVPCF0YzVBqSr0MDYVbXh-zfhT27vCkbr5-6YvIIf7aVUFJNXewFw'; if (!($fp = fopen($filename, "r"))) { die("cannot open ".$filename); } while ($data = fread($fp, 4096)){ $data=eregi_replace(">"."[[:space:]]+"."< ",">< ",$data); if (!xml_parse($xmlparser, $data, feof($fp))) { $reason = xml_error_string(xml_get_error_code($xmlparser)); $reason .= xml_get_current_line_number($xmlparser); die($reason); } Link to comment https://forums.phpfreaks.com/topic/49889-xml-parse-invalid-character-error/#findComment-244740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.