1

I'm creating an XML according to a user input. suppose the user entered one of the XML special characters, i want to replace it to it's XML representation. Now, suppose:

$value = 'bla"bla';

And this is my code:

$value = str_replace(array("&", "<", ">", "\"", "'"), array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;"), $value);
//at this point the value of $value is 'bla&quot;bla'
$attrRoot = $doc->createElement($key, $value);
//at this point the value of $attrRoot->nodeValue is 'bla"bla' again.

I want the value to appear inside my XML like the value of $value. any suggestions?

4

0 回答 0