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("&", "<", ">", """, "'"), $value);
//at this point the value of $value is 'bla"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?