Im having issues with a csv upload script where I need to upload German text into a mysql database for translation purposes.
Everything is UTF8 but when it runs the script and inserts into the database. All the characters are there, umluats show fine but the – (&mdash) and „ or “ just go in blank.
The snippet of text im trying to upload
Actual text in CSV = "Testing – Seit über „Es ist“ Das Unternehmen."
Database after upload = "Testing Seit über Es ist Das Unternehmen."
It uploads the umlauts but just puts a space where the dash and quotes should be.
The CSV is also encoded in utf-8
If I take the utf8_encode() off then the insert breaks at the first special character.
Here is my script
header('Content-Type: text/html; charset=utf-8');
require_once("../cfg/database.php");
mysql_query("SET NAMES 'utf8'");
extract($_POST);
$file = $_FILES['csv']['tmp_name'];
$handle = fopen($file,"r");
$data = array();
$count = 0;
if (!empty($_FILES['csv']['size'])) {
while (($data = fgetcsv($handle,1000,",")) !==FALSE) {
if ($count != 0) {
mysql_query("INSERT INTO table_name SET `text` = '" . utf8_encode($data[5]) . "'") or die(mysql_error());
}
$count++;
}
}
Any help would be much appreciated as I have searched and searched and can not find a solution.
EDIT: Note to self, do not rely on excel to correctly save the encoding of your csv to UTF-8. Just use notepad :)