PHP Classes

Encoding error

Recommend this page to a friend!

      Clean XML To Array  >  All threads  >  Encoding error  >  (Un) Subscribe thread alerts  
Subject:Encoding error
Summary:Fileds splited
Messages:4
Author:Juanjo
Date:2008-01-16 19:36:34
Update:2008-02-13 08:26:33
 

  1. Encoding error   Reply   Report abuse  
Picture of Juanjo Juanjo - 2008-01-16 19:36:34
I have this XML code:

<?xml version="1.0" encoding="utf-8"?>
<array>
<direccion>
<nombre>Dirección Postal</nombre>
<tipo>text</tipo>
<tamano>80</tamano>
<maxvisible>40</maxvisible>
</direccion>
</array>

and after parsing with:

$datos = $converter->parse("fichero.xml");

I got this array:

["direccion"]=>
array(4) {
["nombre"]=>
array(2) {
[0]=>
string(7) "Direcci"
[1]=>
string(10) "ón Postal"
}
["tipo"]=>
string(4) "text"
["tamano"]=>
string(2) "80"
["maxvisible"]=>
string(2) "40"
}


"nombre" field is splited at the accented char. The xml file is correctly saved in utf-8 enconding.

Any help ?
Thanks!

  2. Re: Encoding error   Reply   Report abuse  
Picture of Ivan Enderlin Ivan Enderlin - 2008-01-16 20:03:50 - In reply to message 1 from Juanjo
Problem don't come from my class. Take a look in PHP XML parser (that's what I use here).

  3. Re: Encoding error   Reply   Report abuse  
Picture of Juanjo Juanjo - 2008-01-17 10:37:04 - In reply to message 2 from Ivan Enderlin
Sorry, this is not true.

As comments on the xml_set_character_data_handler php's function, you may control that the function can be called several times for the same entity and maust be concatenated or the entity gots spplited.

I have modified your function from this:

[...]
// or then $contentHandler is a multi-tag content case 2;
else {
$this->pOut[key($this->track)][current($this->track)] = array(
0 => $this->pOut[key($this->track)][current($this->track)],
1 => $contentHandler
);
}
[...]

to simply this:

[...]
// or then $contentHandler is a multi-tag content case 2;
else {

$this->pOut[key($this->track)][current($this->track)] .= $contentHandler;
}
[...]

and your class now can handle this sppliting. I don't know if this can break other features, but works for me.

You have the comment here:
es2.php.net/manual/en/function.xml- ...

Despite this, your class is amazing!

Thanks!

  4. Re: Encoding error   Reply   Report abuse  
Picture of Valentin Valentin - 2008-02-13 08:26:34 - In reply to message 3 from Juanjo
Thank you for this fix! I've got the same problem with german umlauts (ö,ä,ü,ß) - works fine now :)