如何避免php在加载xml文件时破坏umlaut字符?

如何避免php在加载xml文件时破坏umlaut字符?,php,xml-parsing,Php,Xml Parsing,我有一个xml要用php解析,它包含一些umlaut字符。 每个包含字符串的节点都将该字符串包装在cdata标记中,但我的问题在解析xml之前就开始了:当我加载文件时,我还尝试使用file_get_竞赛打印出文件内容,结果相同,umlaut字符被破坏,因此例如,u变为ü。运行htmlentities是徒劳的,因为此时角色已经被破坏。xml编码是utf-8,所以我不知道还有什么可以避免这个问题。有人能帮我吗 编辑: xml示例“locations.xml”: <?xml version=

我有一个xml要用php解析,它包含一些umlaut字符。 每个包含字符串的节点都将该字符串包装在cdata标记中,但我的问题在解析xml之前就开始了:当我加载文件时,我还尝试使用file_get_竞赛打印出文件内容,结果相同,umlaut字符被破坏,因此例如,u变为ü。运行htmlentities是徒劳的,因为此时角色已经被破坏。xml编码是utf-8,所以我不知道还有什么可以避免这个问题。有人能帮我吗

编辑: xml示例“locations.xml”:

<?xml  version="1.0" encoding="utf-8"?>
<locations>
  <location>
    <id>481</id>
    <city><![CDATA[Zürich]]></city>
  </location>
</locations>

不确定它是否有用,但您是否尝试过在php脚本中设置标题?标题的内容类型:text/html;字符集=utf-8';你能提供你的代码吗?PHP在加载文件时不会打断字符。您只是有一个输出问题。请看。我忘记了:这是在一个类中发生的,我只需要解析xml以将数据保存在db parse和save are working by save are working中,您的意思是正确的字符可以正确保存在db中吗?
function parseLocations(){
    $xml = new DOMDocument();
$xml->load('locations.xml');
$xml->preserveWhiteSpace = false;
$data = array();
    $locations = $xml->childNodes->item(0);
    for($i=0; $i<$locations->childNodes->length; $i++){
        $location = $locations->childNodes->item($i);
        if($location->nodeName=="location"){
            $tmp = parseVenue($location);
            $data[] = $tmp;
        }
    }
    echo var_export($data, true); 
}

function parseVenue($location){
    //I need to exclude some of the nodes
    $exclude = array('#text'); 
    $data = array();
    for($i=0; $i<$location->childNodes->length; $i++){
        $tag = $location->childNodes->item($i);
        if(!in_array($tag->nodeName, $exclude)){
            $data[$tag->nodeName] = $tag->nodeValue;
        }

    }
    return $data;
}
array ( 0 => array ( 'id' => '481', 'city' => 'Zürich'), )