title: Converting from HTML entities to UTF-8
body: <p>I have a problem converting some encoded strings to utf-8.</p>
  
  <p>I have a list of strings which according to the documentation are Unicode strings encoded using numeric HTML entities. Some of them are:</p>
  
  <pre><code>$str = 'W&amp;#xc3;&amp;#x96;GER'; // seems to be WÖGER
  $str = 'J&amp;#xc3;&amp;#xbc;rgen'; // seems to be Jürgen
  $str = 'PO&amp;#xc3;&amp;#x9f;NITZ'; // seems to be POßNITZ
  $str = 'SCHL&amp;#xc3;&amp;#x84;GER'; // seems to be SCHLÄGER
  </code></pre>
  
  <p>I want to decode them and convert to utf-8. </p>
  
  <p>I tried both <a href="http://php.net/manual/en/function.mb-convert-encoding.php" rel="nofollow">mb_convert_encoding()</a> with <code>HTML-ENTITIES</code> param as well as <a href="http://php.net/manual/en/function.html-entity-decode.php" rel="nofollow">html_entity_decode()</a>. My best result unexpectedly was with:</p>
  
  <pre><code>html_entity_decode($str, ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
  </code></pre>
  
  <p>and that decoded <code>Jürgen</code> <a href="https://eval.in/593510" rel="nofollow">successfully</a>. However I have no luck decoding other strings from this list. I looked <a href="http://cs.stanford.edu/people/miles/iso8859.html" rel="nofollow">ISO-8859-1</a> encoding table and HTML codes for umlauts there differ from what I have in my list.</p>
  
  <p>My question is: am I missing some obvious decoding step or is there something wrong with the source strings? </p>
  
  <p><strong>Update (2016-06-27):</strong> The original strings were indeed incorrectly encoded. These strings are the result of reading UTF-8 values in Latin-1 context and then encoding individual 1-byte chars as hex entities, so german umlaut <code>ü</code> became <code>Ã¼</code> and was encoded as 2 separate chars. The accepted answer decodes them straight into UTF-8 successfully.</p>