OZONE Asylum
Forums
Server-Side Scripting - Oh my!
PHP: undefined offset reading file
This page's ID:
30315
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
My code is generating an undefined offset. I have a text file filled with lines that may contain comments ( [i]prefix: "//"[/i] ), or data: in the form: [i][number]=[string][/i] . Like an ini file, if the key was always a number in the range 0-31. I'm getting a PHP notice when trying to read. My data [b]is being correctly read.[/b] But I need to fix the error causing the Notices. [quote]PHP output: ed offset: 1 in image.php on line 170 PHP Notice: Undefined offset: 1 in image.php on line 170 PHP Notice: Undefined offset: 1 in image.php on line 170 PHP Notice: Undefined offset: 1 in image.php on line 170 PHP Notice: Undefined offset: 1 in image.php on line 170 # repeating several times[/quote] (1) To double check: if split() returns false, are these two statements equivalent in PHP? if( !$result) continue; # AND: if( $result == False ) continue; [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] [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];[/code] now the error is: [quote]T: 1 in image.php on line 170 PHP Notice: Undefined offset: 1 in image.php line 170 "Undefined offset 1 in image.php";[/quote] (2) What does the error "T: 1 in <file> on line <number>" mean? (3) How do I fix the error Undefined offset?
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »
Maximum Security
OZONE
DHTML/Javascript
Server-Side Scripting - Oh my!
CSS - DOM - XHTML - XML - XSL - XSLT
Stupid Basic HTML
Visual Therapy
Photoshop
Photoshop Pong, Anyone?
***WARNING*** BIG SIG APPROACHING
Photography
3D Modelling & Rendering
Multimedia/Animation
Print Graphics
Holding Pens
Philosophy and other Silliness
Outpatient Counseling
Site reviews!
Mad Scientists' Laboratory
Getting to know the Grail