Jump to content

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...
Link to comment
https://forums.phpfreaks.com/topic/14716-parsing-xml-cdata/
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]
Link to comment
https://forums.phpfreaks.com/topic/14716-parsing-xml-cdata/#findComment-58823
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.