maddogandnoriko Posted April 14, 2009 Share Posted April 14, 2009 I have an xml file loaded into a simplexml object. The xml has a "ö" in it and is getting garbled in the simplexml object. Here is my test code: <?php $seriesURL='http://www.thetvdb.com/api/GetSeries.php?seriesname=krod'; echo 'SeriesURL:'.$seriesURL.'<br><br>'; $data = simplexml_load_file($seriesURL); echo '<br><br>'. ($data->Series->SeriesName); ?> The resulting Series Name is: Kröd Mändoon and the Flaming Sword of Fire Link to comment https://forums.phpfreaks.com/topic/154112-simplexml-and-non-standard-characters/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 14, 2009 Share Posted April 14, 2009 http://www.thetvdb.com/api/GetSeries.php?seriesname=krod seem a valid utf-8 xml file. Try that at the begining of your php : <?php header('Content-Type: text/html; charset=utf-8'); ... ?> And in your output html : <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> ... </body> </html> It tell the browser (or whatever client) that your output is encoded in utf-8. Because the content in the xml is encoded in utf-8 (like it should). Or you can convert your data into ASCII html entities and it will work no matter what encoding you use with htmlentities() like that : <?php ... $output = htmlentities($data->Series->SeriesName, ENT_QUOTES, "UTF-8"); echo $output; ... ?> Don't encode the whole XML, only the data part. http://www.php.net/manual/en/function.htmlentities.php Link to comment https://forums.phpfreaks.com/topic/154112-simplexml-and-non-standard-characters/#findComment-810195 Share on other sites More sharing options...
maddogandnoriko Posted April 14, 2009 Author Share Posted April 14, 2009 Thank you very much. maddogandnoriko Link to comment https://forums.phpfreaks.com/topic/154112-simplexml-and-non-standard-characters/#findComment-810226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.