对于打开的购物车,我使用CSV导入插件,默认情况下,如果缺少任何列字段,则会完全跳过产品。 是否有无论如何我可以读取文件,并用'空'或0替换所有空字段,并将其发送回代码。用某些东西替换空的CSV值 - PHP
跳过下面的检查会导致阅读/放置格式发生偏移!
$fh = fopen($file, 'r');
if(!$fh) die('File no good!');
// Get headings
$headings = fgetcsv($fh, 0, $delim);
$num_cols = count($headings);
$num_rows = 0;
//Read the file as csv
while (($row = fgetcsv($fh, 0, $delim)) !== FALSE) {
//missed product if num columns in this row not the same as num headings
if (count($row) != $num_cols) {
$this->total_items_missed++;
continue;
}
for ($i=0; $i<count($headings); $i++) {
$raw_prod[$headings[$i]] = $row[$i];
}
删除执行检查的4行,具体取决于您对数据所做的操作,可能是您需要的。 – 2011-10-24 19:42:07
只是在这里产生一个偏移,然后$ raw_prod [$ headings [$ i]] = $ row [$ i]; – Neo