michael.davis Posted July 11, 2012 Share Posted July 11, 2012 Once again, as I look at my error_logs, I see another page that has a few errors. [root@ohx-lw-tanager httpd]# tail -f error_log [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined index: SPC in /sync/public/intranet/ohx/spc_feed.php on line 60, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined offset: 1 in /sync/public/intranet/ohx/spc_feed.php on line 66, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined index: SPC MD 1449\n in /sync/public/intranet/ohx/spc_feed.php on line 60, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined offset: 1 in /sync/public/intranet/ohx/spc_feed.php on line 66, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined index: SPC Jul 11, 2012 1730 UTC Day 2 Convective Outlook\n in /sync/public/intranet/ohx/spc_feed.php on line 60, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined offset: 1 in /sync/public/intranet/ohx/spc_feed.php on line 66, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined index: SPC Jul 11, 2012 1630 UTC Day 1 Convective Outlook\n in /sync/public/intranet/ohx/spc_feed.php on line 60, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined offset: 1 in /sync/public/intranet/ohx/spc_feed.php on line 66, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined index: SPC Day 1 Fire Weather Outlook\n in /sync/public/intranet/ohx/spc_feed.php on line 60, referer: http://www/ [Wed Jul 11 13:07:17 2012] [error] [client 205.165.229.243] PHP Notice: Undefined offset: 1 in /sync/public/intranet/ohx/spc_feed.php on line 66, referer: http://www/ I am not sure why this is acting this way. I have hightlighted the areas in the code that the error log is point to. This wasnt an issue before, but now is. Can anyone point out my issue? Thanks! Mike <?php # I'm including the open and close font tags so that undefined # types will be handled gracefully. Since "Freeze Warning" is # not defined, it's displayed in the default link color defined # by the user. Class tags would be better than <font color=#xxxxxx> # cuz then they would change color when selected. $color_table = array( "Tornado Watch" => "<b><font color=#FF0000>,</font></b>", "Severe Thunderstorm Watch" => "<b><font color=#FFA500>,</font></b>", "Flash Flood Warning" => "<b><font color=#8B0000>,</font></b>", ); $spcread_insideitem = false; $spcread_tag = ""; $spcread_title = ""; $spcread_description = ""; $spcread_link = ""; function spc_startElement($spcread_parser, $spcread_name, $spcread_attrs) { global $spcread_insideitem, $spcread_tag, $spcread_title, $spcread_description, $spcread_link; if ($spcread_insideitem) { $spcread_tag = $spcread_name; } elseif ($spcread_name == "ITEM") { $spcread_insideitem = true; } } function spc_endElement($spcread_parser, $spcread_name) { global $spcread_insideitem, $spcread_tag, $spcread_title, $spcread_description, $spcread_link, $color_table; if ($spcread_name == "ITEM") { $title = split(' *- *', $spcread_title); [b]$font = split(',', $color_table[$title[0]])[/b]; printf("<a target='_blank' href='%s'>%s%s%s</a><br>", trim($spcread_link), [b]$font[0],[/b] htmlspecialchars(trim($spcread_title)), [b]$font[1]);[/b] //printf("<span class='BodyText'>%s</span><br>", // htmlspecialchars(trim($spcread_description))); $spcread_title = ""; $spcread_description = ""; $spcread_link = ""; $spcread_insideitem = false; } } function spc_characterData($spcread_parser, $spcread_data) { global $spcread_insideitem, $spcread_tag, $spcread_title, $spcread_description, $spcread_link; if ($spcread_insideitem) { switch ($spcread_tag) { case "TITLE": $spcread_title .= $spcread_data; break; case "DESCRIPTION": $spcread_description .= $spcread_data; break; case "LINK": $spcread_link .= $spcread_data; break; } } } $spcread_xml_parser = xml_parser_create(); xml_set_element_handler($spcread_xml_parser, "spc_startElement", "spc_endElement"); xml_set_character_data_handler($spcread_xml_parser, "spc_characterData"); $spcread_fp = fopen("http://www.spc.noaa.gov/products/spcrss.xml","r") or die("Error reading RSS data."); while ($spcread_data = fread($spcread_fp, 4096)) { xml_parse($spcread_xml_parser, $spcread_data, feof($spcread_fp)) or die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($spcread_xml_parser)), xml_get_current_line_number($spcread_xml_parser))); } fclose($spcread_fp); xml_parser_free($spcread_xml_parser); ?> Quote Link to comment https://forums.phpfreaks.com/topic/265527-undefined-offset/ Share on other sites More sharing options...
psynor Posted July 11, 2012 Share Posted July 11, 2012 This means that the array has only one index and the script is trying to access the second index (which doesn't exist). Keep in mind, the count starts at 0 (zero) Quote Link to comment https://forums.phpfreaks.com/topic/265527-undefined-offset/#findComment-1360819 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.