Reputation:
I've been all over google and haven't been able to find a regex that would parse (correctly) CLI arguments.
Does anyone have in their code library such a thing?
Ideally it would parse all styles of arguments (i.e.: -v -abc --arg=val --arg="val1 val2" --arg "val")
Thanks!
P.S.: This would be used in PHP context (preg)
Upvotes: 5
Views: 838
Reputation: 300845
Have a look at PEAR's Console_Getopt or the Zend Framework Zend_Console_Getopt
Your PHP version may have support for getopt as a built-in also.
Upvotes: 7
Reputation: 5878
Just thought I'd let you know I found a solution.
http://nlindblad.org/2007/05/12/handling-command-line-arguments-in-php/
Upvotes: 0
Reputation: 12900
The global $argv already parses the command line arguments automatically if you're running CLI. Also see: Using PHP from the command line
Upvotes: 0