Apikot
Apikot

Reputation:

Command line instruction parsing

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

Answers (4)

Paul Dixon
Paul Dixon

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

Andrei Serdeliuc ॐ
Andrei Serdeliuc ॐ

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

vartec
vartec

Reputation: 134601

getopt()

Upvotes: 4

acrosman
acrosman

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

Related Questions