Skip to content

foxwoods/getopts

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

getopts

The goal of this project is to build an alternative to php's getopt, which ich really crippled.

All you need

Example

script "test.php"

	<?php
		require_once('getopts.php');
		list($errors, $params, $args) = getopts(array(
			'a' => array('St', 'a'), // param as array
			'b' => 'Vs b long',     // param as string
		));
		if($errors){
			die($errors[0].PHP_EOL);
		}
		echo 'a = '.var_export($params['a'], true).', ';
		echo 'b = '.var_export($params['b'], true).', ';
		echo 'args = '.var_export($args, true).PHP_EOL;
	?>

sample input 1:

	php test.php -a file

output 1:

	a = true, b = false, args = array('file')

-a is given, therefore true. -b is not given. 'file' is not attached to an option and returned as args.

sample input 2:

	php test.php -a --long file -a

output 2:

	a = false, b = 'file', args = array()

-a is given twice, and since a is defined as toggle it's off (false). -b is given (as the long version --long). No other arguments.

License

Creative Commons Attribution 3.0 Unported License

About

getopts - a replacement for php's getopt

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%