Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After reading at your problem, I tried same thing on my machine. What I did is 1. Downloaded xml file on my local machine from the URL you posted. 2. Used your xml parsing script to prepare structure from XML.</p> <p>Amazingly it worked perfectly on my machine, even though XML has Nedelišće keyword. So, I see the problem in the way of reading XML file.</p> <p>It would be easy to debug if you can tell me the way you are reading the xml form google api. Are you using CURL?</p> <p>EDIT ----------------------------------------------- </p> <p>Hi 0plus1,</p> <p>I have prepared one helper function to convert those special chars to html for making it able for parsing..</p> <p>I am pasting entire code here. Use following script..</p> <pre><code>function utf8tohtml($utf8, $encodeTags) { $result = ''; for ($i = 0; $i &lt; strlen($utf8); $i++) { $char = $utf8[$i]; $ascii = ord($char); if ($ascii &lt; 128) { // one-byte character $result .= ($encodeTags) ? htmlentities($char , ENT_QUOTES, 'UTF-8') : $char; } else if ($ascii &lt; 192) { // non-utf8 character or not a start byte } else if ($ascii &lt; 224) { // two-byte character $result .= htmlentities(substr($utf8, $i, 2), ENT_QUOTES, 'UTF-8'); $i++; } else if ($ascii &lt; 240) { // three-byte character $ascii1 = ord($utf8[$i+1]); $ascii2 = ord($utf8[$i+2]); $unicode = (15 &amp; $ascii) * 4096 + (63 &amp; $ascii1) * 64 + (63 &amp; $ascii2); $result .= "&amp;#$unicode;"; $i += 2; } else if ($ascii &lt; 248) { // four-byte character $ascii1 = ord($utf8[$i+1]); $ascii2 = ord($utf8[$i+2]); $ascii3 = ord($utf8[$i+3]); $unicode = (15 &amp; $ascii) * 262144 + (63 &amp; $ascii1) * 4096 + (63 &amp; $ascii2) * 64 + (63 &amp; $ascii3); $result .= "&amp;#$unicode;"; $i += 3; } } return $result; } $curlHandle = curl_init(); $serviceUrl = "http://www.google.com/ig/api?weather=dunjkovec,medimurska,croatia&amp;hl=en"; // setup the basic options for the curl curl_setopt($curlHandle , CURLOPT_URL, $serviceUrl); curl_setopt($curlHandle , CURLOPT_HEADER , 0); curl_setopt($curlHandle , CURLOPT_HTTPHEADER , array("Cache-Control: no-cache","Content-type: application/x-www-form-urlencoded;charset=UTF-8")); curl_setopt($curlHandle , CURLOPT_FOLLOWLOCATION , true); curl_setopt($curlHandle , CURLOPT_RETURNTRANSFER , true); curl_setopt($curlHandle , CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); $data = curl_exec($curlHandle); // echo $data; $data = utf8tohtml($data , false); echo $data; $parser = xml_parser_create("UTF-8"); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); $ok = xml_parse_into_struct($parser, $data, $values); if (!$ok) { $errmsg = sprintf("XML parse error %d '%s' at line %d, column %d (byte index %d)", xml_get_error_code($parser), xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser), xml_get_current_column_number($parser), xml_get_current_byte_index($parser)); } echo "&lt;pre&gt;"; print_r($values); echo "&lt;/pre&gt;"; </code></pre> <p>Hope this will help.</p> <p>Thanks!</p> <p>Hussain.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload