我正在下载远程文本文件并将其导入本地 mysql 数据库。
格式最近已更改为在其中一列内有一个逗号,并导致导入失败,并出现错误“第 1 行 CSV 输入中的字段计数无效”。数据现在看起来像:
"bonita","FL","212025920","2012929","Hooker,Bill"
如何更新此代码片段以允许引号内有逗号?
foreach(explode($lineseparator,$csvcontent) as $line) {
$lines++;
$line = trim($line," \t");
$line = str_replace("\r","",$line);
/************************************
This line escapes the special character. remove it if entries are already escaped in the csv file
************************************/
$line = str_replace("'","\'",$line);
/*************************************/
$linearray = explode($fieldseparator,$line);
$linemysql = implode("','",$linearray);
$linemysql = str_replace("\"","",$linemysql);###code added
$query = "insert ignore into $databasetable values('$linemysql');";