未定义的偏移量:1和2

时间:2014-04-19 10:24:19

标签: php sql undefined offset explode

我正在使用explode函数在sql表中插入文本管道分隔文件。

错误是:

Notice: Undefined offset: 1
Notice: Undefined offset: 2 
Both on line 34

即。

 $list=explode("|",$line);
 $sql="INSERT INTO tb (tb1,tb2,tb3) VALUES('$list[0]','$list[1]','$list[2]')";

请帮忙。

  while (!feof($handler)) // Loop til end of file.
  {
       $line= fgets($handler);     // Read a line
       $list=explode("|",$line);
       $sql="INSERT INTO tb (tb1,tb2,tb3) VALUES('$list[0]','$list[1]','$list[2]')";
       $result= mysql_query($sql,$conn);             
  }

1 个答案:

答案 0 :(得分:0)

如果你不关心价值观,你可以这样做

$list=explode("|", $line) + array('', '', '');

你的数组总是有3个元素。