I'm trying to replace the information inside of an XML node (in an XML file, duh) with PHP5's filesystem functions and SimpleXML. However, PHP has decided to convert all the reserved HTML characters (<, >, &, etc) to their &whatever; equivalents!
Here's my XML file, named pages.xml:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<data type="pages">
<page value="example" title="The first example">
<![CDATA[Just an <b>example</b>...]]>
</page>
<page value="exampleTwo" title="The second example">
<![CDATA[The <i>second</i> example!]]>
</page>
</data>Code: Select all
<?php
$xml = simplexml_load_file("pages.xml");
//This is what I'm changing the second node to:
$xml->page[1] = '<![CDATA[Dude, you should visit <a href="http://example.com">example.com</a>. It\'s truly amazing & inspiring]]>';
$fileHandle = fopen("pages.xml", "w");
fwrite($fileHandle, $xml->asXML());
fclose($fileHandle);
?>Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<data type="pages">
<page value="example" title="The first example">
<![CDATA[Just an <b>example</b>...]]>
</page>
<page value="exampleTwo" title="The second example">
<![CDATA[Dude, you should visit <a href="http://example.com">example.com</a>. It's truly amazing & inspiring]]>
</page>
</data>Code: Select all
<page value="exampleTwo" title="The second example">
<![CDATA[Dude, you should visit <a href="http://example.com">example.com</a>. It's truly amazing & inspiring]]>
</page>Thanks!