title: how to detect encoding of uploaded csv file
body: <p>I`ve have <strong>data.csv</strong> file, that must be uploaded to server , parsed ....</p>
  
  <p>This file can have different encodings. I must detect it and convert to utf8.</p>
  
  <p>At this moment <strong>php</strong> function  <strong>mb_detect_encoding</strong> always return utf8.
  i tryed:</p>
  
  <pre><code>&lt;?php 
  mb_detect_encoding(file_get_contents($_FILES["csv_uploadfile"]["tmp_name"]));
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;?php 
  mb_detect_encoding(file_get_contents($saved_file_path));
  </code></pre>
  
  <p>mb_detect_encoding returns utf8.</p>
  
  <p>if i use bash command </p>
  
  <pre><code>$ file -bi csv_import_1378376486.csv |awk -F "=" '{print $2}'
  </code></pre>
  
  <p>it rerurns iso-8859-1</p>
  
  <p>so when i try </p>
  
  <pre><code>iconv --from-code=iso-8859-1 --to-code=utf-8 csv_import_1378382527.csv 
  </code></pre>
  
  <p>it is not readable.</p>
  
  <p><strong>The real encoding is  cp1251, by i cann`t detect it.</strong>
  Can anyone help me to solve  this problem?</p>