Tutorial :Command line instruction parsing



Question:

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)


Solution:1

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.


Solution:2

getopt()


Solution:3

The global $argv already parses the command line arguments automatically if you're running CLI. Also see: Using PHP from the command line


Solution:4

Just thought I'd let you know I found a solution.

http://nlindblad.org/2007/05/12/handling-command-line-arguments-in-php/


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »