我正在尝试从产品提要中解析一些 CSV 文件。我正在使用下面的代码从 CSV 中获取数据,并逐行处理以插入 MySQL 数据库。出于某种原因,addlashes 函数似乎每隔一段时间就会跳过转义序列。我在这里做错了什么?
while (($data = fgetcsv($fh, 2000, ",")) !== FALSE)
{
$num = count($data);
$nl = 0;
for ($c=0; $c < $num; $c++)
{
$nl++;
if ($c >= 0)
{
if ($nl == 1)
{
$Name = addslashes($data[$c]);
}
if ($nl == 2)
{
$URL = $data[$c];
}
if ($nl == 3)
{
$CatalogName = addslashes($data[$c]);
}
if ($nl == 4)
{
$LastUpdated = $data[$c];
}
}
}
if ($headerRow > 40)
{
$sql = "INSERT INTO table (name,url,catname,updated) VALUES ('$Name','$URL','$CatalogName','$LastUpdated')";
mysqli_query($connection3,$sql) or die("Can't execute query I001.);
}
}