我有一个问题。我有excel文件保存为CSV,我需要用PHP读取该文件,并插入到mysql中,但问题是与字符集专门čćšđž。我尝试了utf8_encode()和几乎所有我能想到的。
Examle:
它插入“Petroviæ”,但它应该是“Petrović”
编辑:
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) <= 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();
?>