title: How to convert special characters in xml using php?
body: <p>There are so many posts for this question. I have gone through all of them but I didn't get the solution as I expected. I need to convert special characters in XML into html entities.</p>
  
  <p>I tried,</p>
  
  <pre><code>&lt;?php
  $xml="&lt;test&gt;This is a xml file which has special characters &lt; &gt; &amp; in it&lt;/test&gt;";
  htmlspecialchars($xml, ENT_XML1, 'UTF-8');//it replaces xml tags too
  ?&gt;
  </code></pre>
  
  <p>Expected output XML string:</p>
  
  <pre><code>&lt;test&gt;This is a xml file which has special characters &amp;lt; $gt; &amp;amp; in it&lt;/test&gt;
  </code></pre>