简体   繁体   English

未定义的偏移量:1和2

[英]Undefined Offset :1 and 2

I am using explode function to insert a text pipe delimited file in sql table . 我正在使用explode函数在sql表中插入文本管道定界文件。

The error is : 错误是:

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

ie. 即。

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

Please help. 请帮忙。

  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);             
  }

If you do not care about values you could do this 如果您不关心值,可以这样做

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

You array would be always has 3 elements. 您的数组将始终具有3个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM