I am trying to display data from a text file, each information on a new row, and the following code works but I get a "Notice: Undefined offset: 1, 2, 3" error messages. I'm not sure if it is because it has reached the end of the file. I don't understand arrays very well as I am a beginner. Also, the text file will be updated with new information so I need the code to be flexible.
Any help to solve this simple php notice message would be appreciated.
<?php
$data = file_get_contents('random.txt');
$rows = explode("\n", $data);
for($i = 0; $i < count($rows); $i++)
{
$temp = explode('|', $rows[$i]);
$random = $temp[0];
$date = $temp[1];
$time = $temp[2];
$alphanumeric = $temp[3];
echo $random . "<br />";
echo $date . "<br />";
echo $time . "<br />";
echo $alphanumeric . "<br />";
}
?>
I get the following "Notice" message at the bottom of the php page...
Notice: Undefined offset: 1 on line 11
Notice: Undefined offset: 2 on line 12
Notice: Undefined offset: 3 on line 13