How to convert special characters in xml using php?



There are so many posts for this question. I have gone through all of them but I dint get the solution as I expected.I need to convert special characters in xml into html entities.


I tried,



<?php
$xml="<test>This is a xml file which has special characters < > & in it</test>";
htmlspecialchars($xml, ENT_XML1, 'UTF-8');//it replaces xml tags too
?>


Expected output xml file:



<test>This is a xml file which has special characters &lt; $gt; &amp; in it</test>

No comments:

Post a Comment