当尝试使用ISO-8859-1编码在PHP中创建XML文件时,似乎&符号已转换为HTML实体,这会导致已转换的字符串出现问题。
<CustomerDescription>The 'Sample' product</CustomerDescription>
成为
<CustomerDescription>The &apos;Sample&apos; product</CustomerDescription>
这一切正常,直到使用loadXML()或save()命令
$xml = "<CustomerDescription>The 'Sample' product</CustomerDescription>";
$dom = new DOMDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->formatOutput = true;
$dom->loadXML($xml);
$dom->save($_SERVER['DOCUMENT_ROOT'].'/folder/'.$filename);