Drumminxx Posted July 15, 2006 Share Posted July 15, 2006 Why do I get these strange characters after parsing some xmlthis is what an xml item looks like:[code]<blurb><![CDATA[ATTIK Leeds creates key art for flagship game – BLACK.]]></blurb>[/code]now the dash you see above "game - BLACK"comes back like thisATTIK Leeds creates key art for flagship game [b]–[/b] BLACK.I found success using str_replace but is there a built-in function I could be using?I couldn't find it if there is... Quote Link to comment https://forums.phpfreaks.com/topic/14716-parsing-xml-cdata/ Share on other sites More sharing options...
Branden Wagner Posted July 16, 2006 Share Posted July 16, 2006 what are you using to parse the xml? Quote Link to comment https://forums.phpfreaks.com/topic/14716-parsing-xml-cdata/#findComment-58802 Share on other sites More sharing options...
OOP Posted July 16, 2006 Share Posted July 16, 2006 check the characters set you are using in your XML document Quote Link to comment https://forums.phpfreaks.com/topic/14716-parsing-xml-cdata/#findComment-58804 Share on other sites More sharing options...
Drumminxx Posted July 16, 2006 Author Share Posted July 16, 2006 I'm thinking that these are some mac characters, them New Yorkers always got to be different and can't just use a PC, but then I don't know much about mac's anyway so I could be wrong.<?xml version="1.0" encoding="UTF-8"?>heres how I'm parsing the xml minus the start, end and data functions[code] $xml_parser = xml_parser_create(); xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,false);//this could probably go but... xml_set_element_handler($xml_parser, "client_startTag", "client_endTag"); xml_set_character_data_handler($xml_parser, "client_tagData"); $file = '../en-us/xml/'.$sub_cat_id[$i][3]; $data = xml_parse($xml_parser,file_get_contents($file)); xml_parser_free($xml_parser); if(!$data) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));[/code]now I've tried several encode, decode functions php offers I just can't seem to find one that works right. here are some functions that I'm using that works just so you can see what kind of characters i'm dealing with[code]function fixchars($text) { $bad = array('’','–','‘'); $good = array('’','–','’'); $text = str_replace($bad, $good, $text); return $text;}function bfixchars($text) { $bad = array('’','–','‘'); $good = array('’','-','’'); $text = str_replace($bad, $good, $text); return $text;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14716-parsing-xml-cdata/#findComment-58823 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.