/ Published in: PHP
URL: http://es2.php.net/features.commandline
seen in comments in http://es2.php.net/features.commandline
Expand |
Embed | Plain Text
<?php function getArgs($args) { $last_arg = null; $out[$key] = $parts[1]; } else { $out[$key] = true; } $last_arg = $key; } $key = $match[1]{$j}; $out[$key] = true; } $last_arg = $key; } else if($last_arg !== null) { $out[$last_arg] = $args[$i]; } } return $out; } /* sample php file.php --foo=bar -abc -AB 'hello world' --baz produces: Array ( [foo] => bar [a] => true [b] => true [c] => true [A] => true [B] => hello world [baz] => true ) */ ?>
Comments
Subscribe to comments
You need to login to post a comment.

Today I write class for parsing command line arguments in php. It's not spam - I hope it help for any scripts.
http://arturgspb.ru/read/php-parser-argumentov-komandnoj-stroki-command-line-arguments-parser.html