我的代码可以很好地排除一行。自从一年以来它没有任何问题,但是现在文件中有一行代码使我的代码错误。
该行:
"26163796",,"85359","RDH001","30551","MDR001",349000,,"CAN",,,,"N","AI","N","O",,,,,2014/11/04,2015/06/30,"56083","C","Cousins Sud","304",,"Imp. Foucher",,"J3B8V3","4318433 Cadastre du Québec","O",2002,,,,,,,,,,,,"30 jours","30 days",,,,,,,"A.I.SEUL","R","PP","IS",,,,2001,,,49,35,,"P",,,,,,49.20,121.40,,"P",8858.70,"PC",,2014,80000,233200,12,4,2,2,2,0,"MT26163796.jpg","6292",,,,,,,,,,,,"Stores, rideaux, pôles, luminaires, lave-vaisselle, porte-poussière électrique, système de son au rez-de-chaussée, projecteur et colonne de son, véranda extérieur, chauffe-eau de piscine, paiement déjà fait pour ouverture de piscine au printemps, piscine récente..suite à l'addendum.","Blinds, curtains and rods, light fixtures, dishwasher, electric dust holder, sound system on main floor, projector and speakers, exterior veranda, water heater for pool, (payment has been done for opening of the pool next Spring.)see addendum...","Réservoir au propane loué $12/mois","Gas tank rented $12/month",,,,,,,,,"O",2015/01/06 01:17:29,,"EV",,,,,,,,,,,,,,,,,"http://passerelle.centris.ca/redirect.aspx?CodeDest=REMAX%26NoMLS=MT26163796",,,"80508","RDD001",,,,,,,,45.29035900,-73.26586700,,,,,,
代码:
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
$num = count($data);
$row++;
$values = '';
for ($c = 0; $c < $num; $c++) {
$values .= "'" . mysql_real_escape_string($data[$c]) . "', ";
}
if ($tableName == 'inscriptions') {
echo ($num) . "\n";
}
$values = substr($values, 0, -2);
$query = "INSERT INTO `" . $tableName . "` ( $columns ) VALUES ( $values )";
$this->_logFile[] = $query;
mysql_query($query) or die('SQL ERROR:' . mysql_error() . ' : ' . $query);
unset($values);
}
事实上,这句话是:“Stores,rideaux,pôles,luminaires,lave-vaisselle,porte-poussièreélectrique,systèmedeson au rez-de-chaussée,projecteur et colonne de son,vérandadxterérieur,chauffe -eau de piscine,paiementdéjàfaitpour ouverture de piscine au printemps,piscinesécente..suiteàl'addendum。“在逗号上被分割,使我的sql查询无效。
请问好吗?
答案 0 :(得分:0)
好的修复:
public function utf8_fopen_read($fileName) {
$fc = iconv('iso-8859-1', 'utf-8', file_get_contents($fileName));
$handle = fopen("php://memory", "rw");
fwrite($handle, $fc);
fseek($handle, 0);
return $handle;
}
$fh = $this->utf8_fopen_read(self::UPLOADED_FILES_TXT . $fileName);
while (($data = fgetcsv($fh, 1000, ',')) !== false) {
$data = array_map("utf8_decode", $data);
...
}