title: Cleaning xml data using str_ireplace function
body: <p>When I ran the Script, it stores blanks in the database. Where am I going wrong. Below is the php script:</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  $request= &lt;&lt;&lt;XML
  &lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:c2b="http://cps.huawei.com/cpsinterface/c2bpayment"&gt;
  &lt;soapenv:Header/&gt;
  &lt;soapenv:Body&gt;
    &lt;c2b:C2BPaymentValidationRequest&gt;
       &lt;TransactionType&gt;PayBill&lt;/TransactionType&gt;
       &lt;TransID&gt;1234560000007031&lt;/TransID&gt;
       &lt;TransTime&gt;20140227082020&lt;/TransTime&gt;
       &lt;TransAmount&gt;123.00&lt;/TransAmount&gt;
       &lt;BusinessShortCode&gt;12345&lt;/BusinessShortCode&gt;
  &lt;BillRefNumber&gt;&lt;/BillRefNumber&gt;
       &lt;InvoiceNumber&gt;&lt;/InvoiceNumber&gt;
  &lt;MSISDN&gt;254722703614&lt;/MSISDN&gt;
       &lt;KYCInfo&gt;
    &lt;KYCName&gt;[Personal Details][First Name]&lt;/KYCName&gt;
    &lt;KYCValue&gt;Hoiyor&lt;/KYCValue&gt;
  &lt;/KYCInfo&gt;
  &lt;KYCInfo&gt;
    &lt;KYCName&gt;[Personal Details][Middle Name]&lt;/KYCName&gt;
    &lt;KYCValue&gt;G&lt;/KYCValue&gt;
  &lt;/KYCInfo&gt;
  &lt;KYCInfo&gt;
    &lt;KYCName&gt;[Personal Details][Last Name]&lt;/KYCName&gt;
    &lt;KYCValue&gt;Chen&lt;/KYCValue&gt;
  &lt;/KYCInfo&gt;
    &lt;/c2b:C2BPaymentValidationRequest&gt;
  &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
   XML;
  //clean the soap input received from Mpesa so that you can parse it as raw XML
  
  $clean_xml = str_replace(['soapenv:','c2b:' ],'', $request);
  $xml = simplexml_load_string($clean_xml);
  //you can extract any payment details using the below code
  $server = '';
  $user = '';
  $pass = '';
  $db  = ''; 
  
   foreach ($xml as $key =&gt; $cur)
  
   {
   //VALUES
    $AccountNo = $cur-&gt;BillRefNumber;
     $TransAmount = $cur-&gt;TransAmount;
    $TransID = $cur-&gt;TransID;
    $KYCInfo = $cur-&gt;KYCInfo;
    $MSISDN = $cur-&gt;MSISDN;                                                                                       
  
  //SAVE TO DATABASE
  $link= mysql_connect($server,$user,$pass) or die (mysql_error());
  $conn= mysql_select_db($db) or die (mysql_error($link));                                                                                                
  $query = "INSERT INTO c2b(TransID,MSISDN,BillRefNumber,KYCInfo,Amount) VALUES('$TransID','$MSISDN','$AccountNo','$KYCInfo','$TransAmount')";
  
  if (!mysql_query($query))
  {
  die('Error: ' . mysql_error());
  }
  else
  {
  echo "New Records added successfully ! &lt;br /&gt;&lt;br /&gt;";       
  }   
  }                                                                                                                  
  
  ?&gt;
  </code></pre>
  
  <p>I suspect that the error is in parsing the xml data using the str_ireplace function. I have looked at the PHP documentation and it seems that I have done everything by the book.</p>