doutuo1908 2013-05-23 13:52
浏览 84

特殊字符(编码问题)[关闭]

I am parsing an xml file. The XML is encoded in utf-8. When words contain special characters, they are distorted. I cannot control the xml file, but is there anything I can do on my end to properly display words?

Example

Shows up as: Skövde
Should Be: Skövde OR Skovde
Shows up as: Kaposvári Rákóczi
Should be: Kaposvári Rákócz  OR Kaspovari Rakocz

Is there anything I can do to convert the first, to the second through php? There are many other cases, these are just too i found really quick.

edit: I'm not sure of the coloring issues. They don't mean anything. edit 2: The xml already contains the words in the "Show up" state I wrote. It's not that I'm reading them wrong. The xml shows Skövde, and I read Skövde. It should really be Skövde. Now I need on my end to convert it to what it should be.

  • 写回答

1条回答 默认 最新

  • drnx3715 2013-05-23 14:01
    关注

    It seems that you are reading the XML correctly (i.e. you get utf-8 strings out of the XML document), however you are not displaying them correctly.

    You are displaying utf-8 strings in a page that's not in utf-8.

    You have to either convert the strings before displaying them:

    (Assuming the encoding of your page is iso-8859-1; if you don't know, look at page informations in your browser)

    mb_convert_encoding($str, "iso-8859-1", "utf-8");
    

    Or set the charset of the page to utf-8:

    header('Content-Type: text/html; charset=utf-8');
    
    // or (in html) :
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    
    评论

报告相同问题?