1

I have an xml file where am replacing the & with & then taking the & converting back to & to insert into the database. My script is not replacing the & with &.

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 Answers2

0

It's impossible to have an XML file with unquoted & characters. It is considered an invalid XML file (impossible to open for any parser).

Why isn't your feed providing the & already in an &amp; state?

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

Community
  • 1
  • 1
Vincent
  • 22,366
  • 18
  • 58
  • 61
0
$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>';