fwrite() running htmlentities() on 'string' parameter?
Posted: Tue Jul 06, 2010 2:19 pm
Simple question and hopefully a simple problem. 
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:
So I'm using SimpleXML w/ PHP5 to change that XML like this:
It works until I look at the XML file after I run the PHP script. It looks like this (note second page node):
What the heck? I checked with some echo's and it turns out fwrite is doing that. The second page node should look like this (not the bizarre mangled version above):
Am I doing something wrong here? 
Thanks!
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!