Zend - The PHP Company




Miscellaneous

Add Code


Cynic  

Type: code fragment
Added by: cynicz
Entered: 27/03/2001
Last modified: 04/12/2000
Rating: - (fewer than 3 votes)
Views: 4113
$argv handling function


<?php
function getargs()
{
    
$argv $GLOBALS['argv'] ;
    
$args['self'] = array_shift$argv ) ;
    while( 
sizeof$argv ) ) {
        
$arg array_shift$argv ) ;
        if( 
'--' == substr$arg ) ) {
            
$eq strpos$arg '=' ) ;
            
$name substr$arg $eq ) ;
            
$val substr$arg $eq ) ;
            
$args[$name][] = $val ;
            continue ;
        }
        if( 
'-' == $arg[0] ) {
            
$name substr$arg ) ;
            if( 
'-' != $argv[0][0] ) {
                
$val array_shift$argv ) ;
            } else {
                
$val '' ;
            }
            
$args[$name][] = $val ;
        }
    }
    return 
$args ;
}


?>


Usage Example


$ php -q somefile.php --path=/foo/bar -t -B quux


Rate This Script





Search



This Category All Categories