title: character encoding in xml feed data
body: <p>I'm loading an XML feed from a remote source like this:</p>
  
  <pre><code>if ($reader = XMLReader::open($url)) {    
      while ($reader-&gt;read()) {
          if ( $reader-&gt;nodeType == XMLREADER::ELEMENT &amp;&amp; $reader-&gt;localName == 'MainNode' ) 
          {
              $node   = $reader-&gt;expand();
              $dom    = new DomDocument();
              $n      = $dom-&gt;importNode($node,true);
              $dom-&gt;appendChild($n);
              $xml    = simplexml_import_dom($n);
              echo($xml-&gt;Remarks); // problem here
           }
      }
  }
  </code></pre>
  
  <p>When I view the page in a browser, it has bad characters in the page like this:</p>
  
  <pre><code>â€œcity within a cityâ€
  </code></pre>
  
  <p>If I use Chrome tools and change the page encoding from Western to UTF8, the problem disappears and the characters all look correct: <code>“city within a city”</code></p>
  
  <p>When I directly insert the raw string into my database, which is a UTF8 db, and then display it on a page, which is also encoded as utf8, it shows up like this: <code>â€œcity within a cityâ€</code>. If I try using <code>utf8_encode</code> on the string, it looks like this: <code>Ã¢Â€Âœcity within a cityÃ¢Â€Â</code>. If I use <code>utf8_decode</code> it shows <code>?city within a city?</code></p>
  
  <p>How should I handle this?</p>