I have this simple code to store soem data in a MySQL table from a CSV file:
$file = "GeoLiteCity-Location.csv";
$handle = fopen($file, "r");
//loop through the csv file and insert into database
do {
$n++;
if ($data[0]) {
$city = str_replace('"', '',$data[3]);
$region = str_replace('"', '',$data[2]);
$latitude = $data[5];
$longitude = $data[6];
$country_id = $mobbuteo::$db->select('_countries', 'country_id', array('code' => str_replace('"', '',strtoupper($data[1]))));
$latlong = $mobbuteo::$db->select('_cities', '*', array('latitude' => $latitude, 'longitude' => $longitude));
if ($country_id[0]['country_id'] !== 0 && $country_id[0]['country_id'] !== '' && $country_id[0]['country_id'] !== NULL)
if (count($latlong) <= 0)
$result = $mobbuteo::$db->insert_update('insert', '_cities', array('country_id' => $country_id[0]['country_id'], 'city' => $city, 'region' => $region, 'latitude' => $latitude, 'longitude' => $longitude));
if (!$result) {
echo($city);
}
}
} while ($data = fgetcsv($handle, 1000, ",", "'"));
For some reasons in the DB cities with special characters in their names gets cutted off.
For example: L·i ThiÍu becomes only L in my DB table. I am using UFT8 General Ci.
What's the problem there? But most importantly how do I get now all those cities with special characters and fixing their names correctly?
Thanks for any suggestion