用某些内容替换空的 CSV 值 - PHP
我使用 CSV 导入插件打开购物车,默认情况下,如果产品缺少任何列字段,则完全跳过产品。 无论如何,我可以读取该文件并将所有空字段替换为“null”或 0 并将其发送回代码。
跳过下面的检查会导致读取/放置格式出现偏移!
$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];
}
Im using a CSV Import plugin for open cart and by default is completely skips products if they are missing any of the column fields.
Is there anyway i can read the file and replace all the empty fields with 'null' or 0 and send it back to the code.
skipping that check below causes an offset in the reading/placing format !
$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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将这两行替换
为
Which 将会用 0 添加所有缺失值
Replace these two lines
with
Which will add any missing values with 0's
尝试
try