title: How to detect which type of chinese encoding has text file?
body: <p>on <a href="http://www.gnu.org/software/libiconv/" rel="nofollow">http://www.gnu.org/software/libiconv/</a> there are like 20 types of encoding for Chinese:</p>
  
  <blockquote>
    <p>Chinese EUC-CN, HZ, GBK, CP936, GB18030, EUC-TW, BIG5, CP950,
    BIG5-HKSCS, BIG5-HKSCS:2004, BIG5-HKSCS:2001, BIG5-HKSCS:1999,
    ISO-2022-CN, ISO-2022-CN-EXT</p>
  </blockquote>
  
  <p>So I have a text file that is not UTF-8. It's ASCII. And I want to convert it to UTF-8 using <code>iconv()</code>. But for that I need to know the character encoding of the source.</p>
  
  <p>How can I do that if I don't know chinese? :(</p>
  
  <p>I noticed that:</p>
  
  <pre><code>$str = iconv('GB18030', 'UTF-8', $str);
  file_put_contents('file.txt', $str);
  </code></pre>
  
  <p>produces an UTF-8 encoded file, while other encodings I tried (CP950, GBK and EUC-CN) produced an ASCII file. Could that mean that <code>iconv</code> is able to detect if the input encoding is wrong for the given string?</p>