手记

〇〇六章 php读取csv文件

<?php
$handle = fopen("1.csv","r");
while ($data = fgetcsv($handle, 1000, ",")) {
$data = eval('return '.iconv('gbk','utf-8',var_export($data,true)).';');//修正乱码
echo $data[0].$data[1].$data[2].$data[3].$data[4].$data[5].$data[6].$data[7].$data[8]."<br>\n";
//插入数据库
$sql = "insert into tb_shucai(leibie, name,danwei,price1,youxiaoqi) values('".$data[0]."','".$data[1]."','".$data[2]."','".$data[4]."','".$data[8]."')";
$ret = mysql_query($sql, $link);
}
fclose($handle);
?>

1人推荐
随时随地看视频
慕课网APP