Topic awaiting preservation: PHP: undefined offset reading file (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: mn |
posted 06-09-2008 01:20
My code is generating an undefined offset. I have a text file filled with lines that may contain comments ( prefix: "//" ), or data: in the form: [number]=[string] . Like an ini file, if the key was always a number in the range 0-31. quote:
code: # first code; works as intented, except it outputs ugly notices $lines = file( $path ) or die( "image.php: could not open: $path" ); foreach( $lines as $line_num => $cur_line ) { $cur_line = rtrim( $cur_line ); # this next line causes notice: list($cur_day, $cur_result) = split("=", $cur_line, 2); # this is line #170
code: # so I tried to validate it, fixing only partial errors: All but 2 errors remain $lines = file( $path ) or die( "image.php: could not open: $path" ); foreach( $lines as $line_num => $cur_line ) { $result = split("=", $cur_line, 2); # now this next line causes error: "Undefined offset 1" if(! $result or !$result[0]) continue; # this is line #170 if($result == False or !$result[1]) { continue; } # not enough elements $cur_day = $result[0]; $cur_result = $result[1];
quote:
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
posted 06-09-2008 11:27
(1) yes. |
Maniac (V) Inmate From: there...no..there..... |
posted 06-09-2008 23:25
I don't have anything to add...just wanted to wave to ninmonkeys Haven't seen you here in quite some time. |
Bipolar (III) Inmate From: mn |
posted 06-10-2008 07:30
That fixed it. |