function doGetopt($version, $args, $short_options, $long_options = null, $skip_unknown = false)
    {
        // in case you pass directly readPHPArgv() as the first arg
        if (PEAR::isError($args)) {
            return $args;
        }

        if (empty($args)) {
            return array(array(), array());
        }

        $non_opts = $opts = array();

        settype($args, 'array');

        if ($long_options) {
            sort($long_options);
        }

        /*
         * Preserve backwards compatibility with callers that relied on
         * erroneous POSIX fix.
         */
        if ($version < 2) {
            if (isset($args[0]{0}) && $args[0]{0} != '-') {
                array_shift($args);
            }
        }

        reset($args);
        while (list($i, $arg) = each($args)) {
            /* The special element '--' means explicit end of
               options. Treat the rest of the arguments as non-options
               and end the loop. */
            if ($arg == '--') {
                $non_opts = array_merge($non_opts, array_slice($args, $i + 1));
                break;
            }

            if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) {
                $non_opts = array_merge($non_opts, array_slice($args, $i));
                break;
            } elseif (strlen($arg) > 1 && $arg{1} == '-') {
                $error = Console_Getopt::_parseLongOption(substr($arg, 2),
                                                          $long_options,
                                                          $opts,
                                                          $args,
                                                          $skip_unknown);
                if (PEAR::isError($error)) {
                    return $error;
                }
            } elseif ($arg == '-') {
                // - is stdin
                $non_opts = array_merge($non_opts, array_slice($args, $i));
                break;
            } else {
                $error = Console_Getopt::_parseShortOption(substr($arg, 1),
                                                           $short_options,
                                                           $opts,
                                                           $args,
                                                           $skip_unknown);
                if (PEAR::isError($error)) {
                    return $error;
                }
            }
        }

        return array($opts, $non_opts);
    }
function doGetopt($version, $args, $short_options, $long_options = null, $skip_unknown = false)
    {
        // in case you pass directly readPHPArgv() as the first arg
        if (PEAR::isError($args)) {
            return $args;
        }

        if (empty($args)) {
            return array(array(), array());
        }

        $non_opts = $opts = array();

        settype($args, 'array');

        if ($long_options) {
            sort($long_options);
        }

        /*
         * Preserve backwards compatibility with callers that relied on
         * erroneous POSIX fix.
         */
        if ($version < 2) {
            if (isset($args[0]{0}) && $args[0]{0} != '-') {
                array_shift($args);
            }
        }

        reset($args);
        while (list($i, $arg) = each($args)) {
            /* The special element '--' means explicit end of
               options. Treat the rest of the arguments as non-options
               and end the loop. */
            if ($arg == '--') {
                $non_opts = array_merge($non_opts, array_slice($args, $i + 1));
                break;
            }

            if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) {
                $non_opts = array_merge($non_opts, array_slice($args, $i));
                break;
            } elseif (strlen($arg) > 1 && $arg{1} == '-') {
                $error = Console_Getopt::_parseLongOption(substr($arg, 2),
                                                          $long_options,
                                                          $opts,
                                                          $args,
                                                          $skip_unknown);
                if (PEAR::isError($error)) {
                    return $error;
                }
            } elseif ($arg == '-') {
                // - is stdin
                $non_opts = array_merge($non_opts, array_slice($args, $i));
                break;
            } else {
                $error = Console_Getopt::_parseShortOption(substr($arg, 1),
                                                           $short_options,
                                                           $opts,
                                                           $args,
                                                           $skip_unknown);
                if (PEAR::isError($error)) {
                    return $error;
                }
            }
        }

        return array($opts, $non_opts);
    }
function doGetopt ( $ version , $ args , $ short_options , $ long_options = null , $ skip_unknown = false ) { // in case you pass directly readPHPArgv() as the first arg if ( PEAR :: isError ( $ args ) ) { return $ args ; } if ( empty ( $ args ) ) { return array ( array ( ) , array ( ) ) ; } $ non_opts = $ opts = array ( ) ; settype ( $ args , 'array' ) ; if ( $ long_options ) { sort ( $ long_options ) ; } /*
         * Preserve backwards compatibility with callers that relied on
         * erroneous POSIX fix.
         */ if ( $ version < 2 ) { if ( isset ( $ args [ 0 ] { 0 } ) && $ args [ 0 ] { 0 } != '-' ) { array_shift ( $ args ) ; } } reset ( $ args ) ; while ( list ( $ i , $ arg ) = each ( $ args ) ) { /* The special element '--' means explicit end of
               options. Treat the rest of the arguments as non-options
               and end the loop. */ if ( $ arg == '--' ) { $ non_opts = array_merge ( $ non_opts , array_slice ( $ args , $ i + 1 ) ) ; break ; } if ( $ arg { 0 } != '-' || ( strlen ( $ arg ) > 1 && $ arg { 1 } == '-' && ! $ long_options ) ) { $ non_opts = array_merge ( $ non_opts , array_slice ( $ args , $ i ) ) ; break ; } elseif ( strlen ( $ arg ) > 1 && $ arg { 1 } == '-' ) { $ error = Console_Getopt :: _parseLongOption ( substr ( $ arg , 2 ) , $ long_options , $ opts , $ args , $ skip_unknown ) ; if ( PEAR :: isError ( $ error ) ) { return $ error ; } } elseif ( $ arg == '-' ) { // - is stdin $ non_opts = array_merge ( $ non_opts , array_slice ( $ args , $ i ) ) ; break ; } else { $ error = Console_Getopt :: _parseShortOption ( substr ( $ arg , 1 ) , $ short_options , $ opts , $ args , $ skip_unknown ) ; if ( PEAR :: isError ( $ error ) ) { return $ error ; } } } return array ( $ opts , $ non_opts ) ; }
The actual implementation of the argument parsing code.

@param int    $version       Version to use
@param array  $args          an array of command-line arguments
@param string $short_options specifies the list of allowed short options
@param array  $long_options  specifies the list of allowed long options
@param boolean $skip_unknown suppresses Console_Getopt: unrecognized option

@return array
The actual implementation of the argument parsing code .