Jump to content

Archived

This topic is now archived and is closed to further replies.

Drumminxx

parsing xml cdata

Recommended Posts

Why do I get these strange characters after parsing some xml

this 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 this

ATTIK 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...

Share this post


Link to post
Share on other sites
check the characters set you are using in your XML document

Share this post


Link to post
Share on other sites
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('&rsquo;','&ndash;','&rsquo;');
$text = str_replace($bad, $good, $text);
return $text;
}

function bfixchars($text) {
$bad = array('’','–','‘');
$good = array('’','-','’');
$text = str_replace($bad, $good, $text);
return $text;
}

[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.