title: Creating XML in PHP using SimpleXML with special characters
body: <p>I am working on project in <code>flex 3</code>, where user enters some text which is to be stored in a <code>mysql</code> database and shown later. I am using <code>XML</code> for data transfer from flex to php and vice-versa. <code>SimpleXMLElement</code> in <code>php</code> is being used to create the <code>XML</code>. The problem is the <code>XML</code> breaks on special characters.</p>
  
  <p>Here is sample code:</p>
  
  <p>FLEX:</p>
  
  <pre><code>var someXML:XML = &lt;root&gt;&lt;data&gt;somedata&lt;/data&gt;&lt;data&gt;...&lt;/data&gt; ... &lt;/root&gt;
  var data:Object = {};
  data.xmlData = someXML;
  
  saveDataService.send(data);
  </code></pre>
  
  <p>Here <code>somedata</code> is the data entered by the user. In <code>php</code>, I extract the <code>someXML</code> using <code>SimpleXMLElement</code> and store it to <code>mysql</code>. There is no problem till here. Even if <code>somedata</code> has special characters its working fine and data is stored properly.</p>
  
  <p>Now, in the other case, getting data from database and showing in flex, the response from the php breaks with an error:</p>
  
  <blockquote>
    <p><em>SimpleXMLElement::addChild() [simplexmlelement.addchild]:
    unterminated entity reference</em></p>
  </blockquote>
  
  <p>I tried using <code>urlencode</code> in php, and <code>decodeURI</code> function in flex, but the decoded string is not the same, few special characters are still <code>%xy</code> after decoding.</p>
  
  <p>How do I solve this problem?</p>