title: Read .csv ANSI file and write to mysql
body: <p>I have one problem. I have excel file saved as CSV and I need to read that file with PHP and insert into mysql but problem is with char set specifically čćšđž. I tried utf8_encode() and almost everything I could think of.</p>
  
  <p>Examle:</p>
  
  <p>It inserts "Petroviæ" but it should be "Petrović"</p>
  
  <p>EDIT:</p>
  
  <pre><code>&lt;?php
  
  mysql_connect("localhost", "user", "pw");  
  mysql_select_db("database");  
  
  
  $fajl = "Prodajna mreza.csv"; 
  $handle = @fopen($fajl, "r");
  if ($handle) {
      $size = filesize($fajl);
  
      if(!$size) {
          echo "File is empty.\n";
          exit;
      }
  
      $csvcontent = fread($handle,$size);
      $red = 1;
  
      foreach(explode("\n",$csvcontent) as $line) {
          if(strlen($line) &lt;= 20)
          {
              $red++;
              continue;
          }
          if($red == 1)
          {
              $red++;
              continue;
          }
          $nesto = explode(",", $line);
  
          if($nesto[0] == '')
              continue;
  
          mysql_query("INSERT INTO table(val1, val2, val3, val4, val5, val6, val7, val8) VALUES ('".$nesto[0]."','".$nesto[1]."','".$nesto[2]."','".$nesto[3]."','".$nesto[4]."','".$nesto[5]."','".$nesto[6]."','".$nesto[7]."')");  
  
          $red++;
      }
      fclose($handle);
  }
  mysql_close();
  ?&gt;
  </code></pre>