Your arguments passed during the command will be in the global $argv , as well as the super global $_SERVER["argv"] with $argv[0] and $_SERVER["argv"][0] , which is called.
Useful parsing function, e.g. calling ./myscript.php --user=root --password=foobar
function parse_argvs(){ if( $params = $_SERVER["argv"] ){ $file = array_shift( $params ); while( $params ){ $param = array_shift( $params ); switch( strspn( $param, "-" ) ){ case( 1 ): $OPTS[ trim( $param, " -" ) ] = array_shift( $params ); break; case( 2 ): list( $key, $value ) = explode( "=", $param ); $OPTS[ trim( $key, " -" ) ] = $value; break; default: $OPTS[ $param ] = true; break; } } } return $OPTS ?: array(); }
Something like
$parsed = parse_argvs(); echo $parsed['user']; //root echo $parsed['password']; //password
These are the actual command line arguments passed during the call. Hope this helps.
source share