samejack / php-argv
PHP 命令行参数解析。
1.0.3
2020-07-15 12:28 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- php-coveralls/php-coveralls: *@stable
- phpunit/phpunit: ~4.8|~5.7
- squizlabs/php_codesniffer: *@stable
This package is auto-updated.
Last update: 2024-09-17 12:00:33 UTC
README
PHP 命令行界面(CLI)参数解析器。PHP-Argv 可以解析复杂模式,例如以下内容:
使用 Composer 安装
composer require samejack/php-argv
命令行示例
$ ./example/bin-cli -h 127.0.0.1 -u=user -p passwd --debug --max-size=3 test
Array
(
[h] => 127.0.0.1
[u] => user
[p] => passwd
[debug] => 1
[max-size] => 3
[test] => 1
)
PHP 示例
<?php require_once(__DIR__ . '/vendor/autoload.php'); $argvParser = new \samejack\PHP\ArgvParser(); $string = '-h 127.0.0.1 -u=user -p passwd --debug --max-size=3 test'; print_r($argvParser->parseConfigs($string));
输出
Array ( [h] => 127.0.0.1 [u] => user [p] => passwd [debug] => 1 [max-size] => 3 [test] => 1 )
许可证
Apache License 2.0