[ciapug] explode goes boom?
Chris Van Cleve
vanish at dreamscapevisionery.com
Fri Mar 17 14:51:00 CST 2006
Alright, here's another one of those "I brought my code into PHP 5
from PHP 4 and now I get errors!" things. Granted, this just throws a
PHP_NOTICE, but I hate log bloat so I'm looking to reduce it. THe
code snippet in question follows (part of a forms class):
// Check for <select> options
$selOptions = '';
if(count($options)>0)
{
foreach($options as $value=>$text)
{
if(empty($value) || empty($text))
{
throw new Exception('Invalid value or text for <' . $type . '>
element');
}
$value = explode('|',$value);
$value = ($value[1] == 'selected') ? $value[0] . '"
selected=true"' : implode('',$value);
$selOptions .= '<option value="' . $value . '">' . $text . '</
option>';
}
}
The $options var is an array of key=>value pairs. The bottom segment
is there to parse the key for |selected to set an option in a select
list as the default. The code works fine, but throws the following in
my apache log for every option without |selected in the key (edited
to preserve sanity):
[error] PHP Notice: Undefined offset: 1 in forms.inc.php on line ##
I understand WHY it's throwing the error. What I'm stuck on is
finding an elegant way to get around it. ;)
Any suggestions welcome.
Chris VC
P.S. Subversion beats the pants off of CVS and a three tiered
delivery system using it as the SCM is absolutely the best solution
available today! I'm loving it! Thanks for everyone's input on that.
More information about the ciapug
mailing list