|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-06 20:35 UTC] tcreamean at starsolutionsllc dot com
Description:
------------
When I parse a xml file with fopen with latian accents it returns the word chopped off in php 5.2.3.
So Austr?lia comes back on the web page like this ?lia in 5.2.3.
When I downgraded to 4.4.7 all is working great Austr?lia comes back as Austr?lia.
Reproduce code:
---------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<accessNumbers>
<accessCntry>
<countryName>Alemanha</countryName>
<countryID>96</countryID>
<dialingCode>49</dialingCode>
</accessCntry>
<accessCntry>
<countryName>Argentina</countryName>
<countryID>14</countryID>
<dialingCode>54</dialingCode>
</accessCntry>
<accessCntry>
<countryName>Austr?lia</countryName>
<countryID>20</countryID>
<dialingCode>61</dialingCode>
</accessCntry>
</accessNumbers>
<?php
if (!($fp=@fopen("http://xml.cordiaip.com/?ixAcct=accessNumbersCountries&langId=3","r"))) die ("Couldn't open XML.");
$usercount=0;
$userdata=array();
$state='';
if (!($xml_parser = xml_parser_create('iso-8859-1'))) die("Couldn't create parser.");
//xml_parser_set_option($fp, XML_OPTION_CASE_FOLDING, 0);
//xml_parser_set_option($fp, XML_OPTION_SKIP_WHITE, 1);
function startElementHandler ($parser,$element,$attrib){
global $usercount, $userdata, $state;
switch ($element) {
case $element=="ACCESSCNTRY" : {
$userdata[$usercount]["id"] = $attrib["ID"];
break;
}
default : {
$state = $element;
break;
}
}
}
function endElementHandler ($parser,$element){
global $usercount, $userdata, $state;
$state='';
if($element=="ACCESSCNTRY") {
$usercount++;
}
}
function characterDataHandler ($parser, $data) {
global $usercount, $userdata, $state;
if (!$state) {
return;
}
if ($state == "COUNTRYNAME") {
$userdata[$usercount]["countryname"] = $data;
}
if ($state == "COUNTRYID") {
$userdata[$usercount]["countryID"] = $data;
}
}
xml_set_element_handler($xml_parser,"startElementHandler","endElementHandler");
xml_set_character_data_handler( $xml_parser, "characterDataHandler");
while( $data = fread($fp, 8192)){
if(!xml_parse($xml_parser, $data, feof($fp))) {
break;
}
}
xml_parser_free($xml_parser);
for ($i=0;$i<$usercount; $i++) {
$x = $i+1;
echo $userdata[$i]["countryID"];
echo $userdata[$i]["countryname"];
}
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 06:00:02 2025 UTC |
Hello rrichards, Sorry I did do a search and got nothing back several times as well as poring over the manuals to find a hint about this. I have never seen this behavior before with a array getting chunked on a accent it was unexpected behavior from a array call. So I call the array twice and concatenated the values to return the true whole value of the element which is now in two chunks. I don't know why this is expected behavior when 4.4.7 returns a whole value of countryname O well I am sure there is a good reason. Thanks for your help and tips for tracking this down keep up the good work. if ($state == "COUNTRYNAME") { $userdata[$usercount]["countryname"] = $userdata[$usercount]["countryname"].$data;