【发布时间】:2018-01-08 12:14:41
【问题描述】:
我有一个脚本,它从 csv 导入数据并从导入到 sql 表中的数据创建变量。一切正常,但错误日志因未定义的偏移错误而变得疯狂。
从我读到的内容来看,这是因为它只找到索引 [0],所以任何其他人都会抛出错误。
我查看了以下内容,但似乎无法让建议发挥作用:
PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"
PHP Notice: Undefined offset error when importing from .csv 还有更多...
代码如下:
$filename='XXXXX_'.$today.'.csv';
$url=$proto.$user.':'.$pass.'@'.$server.$path.$filename;
$csv_data=file_get_contents($url);
foreach(preg_split("/((\r?\n)|(\r\n?))/", $csv_data) as $line){
list($type, $id, $ref) = explode(',', $line);
错误是在'list'和'explode'这行代码产生的。
抱歉,对此很陌生,已经阅读了多篇关于“为什么”的文章只是没有找到修复程序,这是我填充错误日志的唯一错误类型。任何帮助将不胜感激。
【问题讨论】:
标签: php list undefined offset explode