title: Escaping xml characters in Codeigniter/php
body: <p>I am trying to save data from my xml file into the mysql database using codeigniter &amp; php. But I couldn't find a way to escape special xml characters to save my data from the xml file to my table, cache_table. </p>
  
  <pre><code> Code:
  
   $xml_source = str_replace(array("&amp;amp;", "&amp;"), array("&amp;", "&amp;amp;"),file_get_contents('XML/customer.xml'));
  
  $xml = simplexml_load_string($xml_source);  
  foreach($xml as $row )
  {
   $attr = $row-&gt;attributes();
  
  $results[] = array('CustomerAccountNumber' =&gt; $this-&gt;db-&gt;escape_str($attr-&gt;CustomerAccountNumber),'Desciption' =&gt; $this-&gt;db-&gt;escape_str($attr-&gt;Desciption) ):
  
  $this-&gt;db-&gt;insert_batch('cache_cust',$results); 
  </code></pre>
  
  <p>But I am getting this error:</p>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
    <p>simplexml_load_string(): Entity: line 37: parser error : Unescaped '&lt;' not allowed in attributes values.</p>
  </blockquote>
  
  <p><strong>customer.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" standalone="yes"?&gt;
  &lt;Rows&gt;
  &lt;Row CustomerAccountNumber="12" Name="Arj" Desciption="PJ psm" /&gt;  
  &lt;Row CustomerAccountNumber="1" Name="Aj" Desciption="*/Artic" /&gt;
  &lt;Row CustomerAccountNumber="2" Name="smla" Desciption="&amp; light" /&gt;
  &lt;Row CustomerAccountNumber="3" Name="alik" Desciption="*/Artic" /&gt;
  &lt;Row CustomerAccountNumber="4" Name="wqla" Desciption="" /&gt;
  &lt;Row CustomerAccountNumber="5" Name="walij" Desciption="16-17" /&gt;
  &lt;Row CustomerAccountNumber="6" Name="li" Desciption="sales@llil.com" /&gt;
  &lt;/Rows&gt;
  </code></pre>
  
  <p>How can I avoid this error and avoid special xml characters so that my code save all the records from the xml file into the database?</p>