title: str_replace &amp;: Converting &amp; to its & character in PHP
body: <p>I have some data in a database that I need represented in an XML file, but the data is different for each request, so the XML file is generated through PHP. For example purposes, let's say this is the text in the db:</p>
  
  <p><code>Hello &amp;amp; Goodbye</code></p>
  
  <p>I've tried using the following to get the above (set to the <code>$example</code> variable) to show up as <code>Hello &amp; Goodbye</code> in the generated XML:</p>
  
  <p><code>$example = mb_convert_encoding($example, "utf-8", "HTML-ENTITIES" );</code></p>
  
  <p><code>$example = htmlspecialchars_decode($example);</code></p>
  
  <p><code>$example = html_entity_decode($example);</code></p>
  
  <p><code>$example = str_replace("&amp;amp;", "&amp;", $example);</code></p>
  
  <p>These lines will replace other entities, like <code>&amp;quot;</code>, to their proper characters, but not <code>&amp;amp;</code>. Any idea how to get this working correctly?</p>