html - XML Parsing - PHP encoding -
i have big xml (>15mb) , have read it, parse it, , store values in db. problem is, xml's come in in differents formats (utf-8, iso-8859-1).
with utf-8 no prob. iso-8859-1 giving me huge problems!! tags come special charachters not parsed correctly xmlreader , readouterxml()
tryed with, no luck
$xml = new xmlreader; $xml->open($import_file,'iso-8859-1'); tried with:
- utf8_encode
- mb_convert_encoding($stringxml, 'utf-8' );
- iconv("iso-8859-1", "utf-8//translit", $stringxml);
the xml (simplified)
- tag (id) --> no problem
- tag (baños) --> problem
xml:
<?xml version="1.0" encoding="iso-8859-1"?> <data> <id><![cdata[5531]]></id> <baños><![cdata[0]]></baños> </data> none of them helped me.
what internal encoding in php? can check echo mb_internal_encoding();.
if utf-8, mb_convert_encoding($data, "utf-8") won't anything, because third parameter $from_encoding "utf-8" already.
you have provide source encoding third parameter function.
so maybe trick:
//check encoding data has? $encoding = mb_detect_encoding($data); if($encoding != "utf-8"){ //specify encoding convert utf-8 $data = mb_convert_encoding($data, "utf-8", $encoding); }
Comments
Post a Comment