I'm trying to parse an $agrv array that contain options (without
square brackets): [-a "abc" -b "bbc" "bcc" -d "dbc" -e -f]
I use ArrayIterator to iterate through the line:
- whenever it reach /-\w/, it read through the following qoutes
until it reach another /-\w/.
The problem is it seems the $iterator->valid() always return TRUE and
cause infinte loop.
function parseOptions ( $argStream, $handler ) {
//Chop first useless argument -- argv[0]
array_shift ( $argStream ) ;
//Initiate ArrayObject for iterator
$arrayobject = new ArrayObject ( $argStream ) ;
//Initiate iterator for iteration
$iterator = $arrayobject->getIterator();
//If options is set first
if( $iterator->valid() && preg_match ( '/^-\w$/', $iterator->current()
) ) {
//iterate through whole argument stream
for ( ; $iterator->valid(); $iterator->next() ) {
//Check if reached next option
if( preg_match ( '/^-\w$/', $opts =
$iterator->current() ) ) {
//Get current options
$currOpt = $opts;
//echo "$currOpt\n";
//Test if next stream is an option
for ($iterator->next(); $iterator->valid();
$iterator->next() ) {
if ( preg_match ( '/^-\w$/', $opts =
$iterator->current() ) ) {
//echo "$currOpt $opts\n";
//$handler($currOpt, $opts);
$currOpt = $opts;
}
var_dump($iterator->valid());
}
}//End if
//echo "$currOpt $opts\n";
//$handler($currOpt, $opts);
}// End for
//If option is not set first.
} else {
//Try other approach.
}// End if
}
I've no idea what is going on.
Please help.
Regards,
Panguin
--
筆使文富,卻使人窮。
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php