If you do not care about values you could do this
$list=explode("|", $line) + array('', '', '');
You array would be always has 3 elements.
Question
I am using explode function to insert a text pipe delimited file in sql table .
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);
}
Solution
If you do not care about values you could do this
$list=explode("|", $line) + array('', '', '');
You array would be always has 3 elements.