开发者

PHP XMLReader Special Characters

开发者 https://www.devze.com 2023-03-05 16:52 出处:网络
I am using XMLReader, more specifically, Jeremy Johnstone\'s plist processer to process a plist XML file. Some of the strings in the XML file contain special characters. One example is \"Frédéric Ch

I am using XMLReader, more specifically, Jeremy Johnstone's plist processer to process a plist XML file. Some of the strings in the XML file contain special characters. One example is "Frédéric Chopin". When I try to print strings with 开发者_如何学运维special characters, they are not being displayed correctly. For example, "Frédéric Chopin" is shown as "Frédéric Chopin" instead.

What can I do so the string is displayed as "Frédéric Chopin"? Thanks!


That looks like a UTF-8 string misinterpreted as some other encoding. You can use iconv() or mb_convert_encoding() to convert into whatever your site uses. I recommend the second one since it can generate HTML entities:

<?php
echo mb_convert_encoding($input, 'HTML-ENTITIES', 'UTF-8');


This has to do with the encoding. Be sure the display encoding matches the XML encoding, (e.g. UTF-8). I am not familiar with that plist processor, but it is possible you may have to set the encoding for the parser as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消