我有一个具有以下结构的csv文件:
a; b; c,c c; d
Run Code Online (Sandbox Code Playgroud)
当我尝试处理它时,它表示偏移量2和3未定义.我花了一段时间才意识到这是由于,并且不知道如何解决这个问题.如果我删除,一切运行正常.
这是我的处理功能:
function process_csv($file) {
$file = fopen($file, "r");
$data = array();
while (!feof($file)) {
$csvdata = fgetcsv($file);
$data[] = explode(';', $csvdata[0]);
}
fclose($file);
return $data;
}
Run Code Online (Sandbox Code Playgroud)
试图fgetcsv($file);为fgetcsv($file, '"');,但没有帮助.
Mar*_*arc 12
您的问题是,fgetcsv fgetcsv默认使用分隔符.您需要将其更改为,.那你就不需要;了:)
function process_csv($file) {
$file = fopen($file, "r");
$data = array();
while (!feof($file)) {
$data[] = fgetcsv($file, null, ';');
}
fclose($file);
return $data;
}
Run Code Online (Sandbox Code Playgroud)