PHP函数不清理我的XML文件

时间:2013-10-16 12:30:11

标签: php xml

我有一个xml文件,其中替换了&与&然后将&转换回&插入数据库。我的剧本并没有取代&与&

function xml_entities($string) {
return strtr(
    $string, 
    array(
        "&" => "&",
    )
);
}

$content=xml_entities(file_get_contents("http://www.site.com/feeds/xxxx/property.xml"));
file_put_contents("cleanme.xml",$content);
echo "File clean complete".'<br>';

2 个答案:

答案 0 :(得分:1)

$content=file_get_contents("http://www.site.com/feeds/xxxx/property.xml");
file_put_contents("cleanme.xml", str_replace("&", "&amp;", $content));

echo "File clean complete".'<br>';

答案 1 :(得分:0)

使用带有不带引号的&字符的XML文件是不可能的。它被认为是无效的XML文件(无法为任何解析器打开)。

为什么您的Feed未提供&状态的&amp;

请参阅:How do I escape ampersands in XML so they are rendered as entities in HTML?