这是我的代码。每当我执行此操作时,数据都会以双引号作为“公园大道”存储在数据库中。
if ($_FILES["csv_file"]["size"] > 0)
{
//get the csv file
$file = $_FILES["csv_file"]["tmp_name"];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
mysql_query("INSERT INTO add_product(product_id, product_name, date) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
//
//redirect
header('Location: http://abcd.adisoftronics.in/index.php/abc/csv_1?success=1');
die;
}
最佳答案
最简单的方法是手动替换它们。
if ($data[0]) {
mysql_query("INSERT INTO add_product(product_id, product_name, date) VALUES
(
'".str_replace('"','',addslashes($data[0]))."',
'".str_replace('"','',addslashes($data[1]))."',
'".str_replace('"','',addslashes($data[2]))."'
)
");
}
如果你想取出更多的字符,你应该检查像 htmlspecialchar() 这样的函数。
关于php - 如何在读取 fgetcsv 时删除数据库中存储的双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30479725/