Php 无法使用Html Umlauts分析xml文件

Php 无法使用Html Umlauts分析xml文件,php,simplexml,special-characters,diacritics,Php,Simplexml,Special Characters,Diacritics,我使用以下代码解析xml文件: $file = file_get_contents('test.xml'); $xml = $file; echo '<pre>'; $xml = htmlentities_decode ($xml); print_r (simplexml_load_string($xml)); function htmlentities_decode( $string ){ $trans = get_html_translation_table(HTML_E

我使用以下代码解析xml文件:

$file = file_get_contents('test.xml');
$xml = $file;
echo '<pre>';

$xml = htmlentities_decode ($xml);
print_r (simplexml_load_string($xml));

function htmlentities_decode( $string ){
  $trans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
  $trans = array_flip($trans);
  return strtr($string, $trans);
}
$file=file\u get\u contents('test.xml');
$xml=$file;
回声';
$xml=htmlentities\u decode($xml);
print_r(simplexml_load_string($xml));
函数htmlentities\u decode($string){
$trans=获取html翻译表(html实体、ENT引号);
$trans=数组翻转($trans);
返回strtr($string,$trans);
}
我的xml文件有如下解码的UMLAUT:
&amul
ß

我必须如何解码/编码我的输出,我必须解码/编码它们,它们以与上面相同的方式显示?(
&amul;
ß;
)。 简单的xml不能直接读取它们,所以我必须先解码它们,简单的xml可以处理它。 之后(在pasring之后),我想将作为utf8保存到数据库中。
要做到这一点,最好的方法是什么?

您是否尝试过htmlspecialchars\u解码($str)?尝试将xml中的字符编码设置为utf8,并使用umlauts等将cdata添加到包含文本的所有节点。应该能够不需要编码任何字符,然后。。。