PHPackages                             stk2k/argparser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. stk2k/argparser

ActiveLibrary[CLI &amp; Console](/categories/cli)

stk2k/argparser
===============

Parser for command line options

0.2.0(4y ago)11.7k2MITPHPPHP &gt;=7.2CI failing

Since Nov 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/stk2k/argparser)[ Packagist](https://packagist.org/packages/stk2k/argparser)[ Docs](https://github.com/stk2k/argparser)[ RSS](/packages/stk2k-argparser/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (6)Used By (2)

Parser for command line options
===============================

[](#parser-for-command-line-options)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7e63ca89a898eaf0b2e9e7653b9308c7ba6e26854bec7df9c7d2ff1bd37ffbe1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746b326b2f6172677061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stk2k/argparser)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/c062710f4e1f80568f0948038fd5c9da9e2a8e302cd3d51a00452fa36ec84169/68747470733a2f2f7472617669732d63692e6f72672f73746b326b2f6172677061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/stk2k/argparser)[![Coverage Status](https://camo.githubusercontent.com/ff3dfb3849730b36b3a8af7968134c59b365ab3ffcf5a764f37cffeb90b46253/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f73746b326b2f6172677061727365722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/stk2k/argparser?branch=master)[![Code Climate](https://camo.githubusercontent.com/8a0ecd8b0c20145be375adb77c57c5233d4a37b3d294160530041d89adae013e/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f73746b326b2f6172677061727365722f6261646765732f6770612e737667)](https://codeclimate.com/github/stk2k/argparser)[![Total Downloads](https://camo.githubusercontent.com/a62e720faa79846963a1b9095144ab6a63e8ef8c91420e799aaf755fe2c6cf07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746b326b2f6172677061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stk2k/argparser)

Description
-----------

[](#description)

Parser for command line options

Feature
-------

[](#feature)

- No need to setup complex configuration
- short options: -abc means a/b/c switches(returns \[a=&gt;true, b=&gt;true, c=&gt;true\])
- long options: --a-key value/--a-key=value returns associative array(\['a-key'=&gt;value\])
- ordered options: "command a b c" returns ordered array(\[a, b, c\])

Parameters
----------

[](#parameters)

```
ArgParser::parse(array $args = null, array $required =[], array $defaults = []);
```

arg nameexplain$argsspecify arguments(if omitted, global $argv is used)$requiredspecify required options$defaultsspecify option default valuesDemo
----

[](#demo)

### \[01\] Parse command line

[](#01-parse-command-line)

```
use stk2k\argparser\ArgParser;

$args = ArgParser::parse();     // script.php a b -c --favorite-food="Fried potato"
print_r($args);
//Array
//(
//    [0] => /path/to/script.php
//    [1] => a
//    [2] => b
//    [-c] => 1
//    [--favorite-food] => Fried potato
//)
```

Requirement
-----------

[](#requirement)

PHP 7.2 or later

Installing stk2k/argparser
--------------------------

[](#installing-stk2kargparser)

The recommended way to install stk2k/argparser is through [Composer](http://getcomposer.org).

```
composer require stk2k/argparser
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

License
-------

[](#license)

[MIT](https://github.com/stk2k/argparser/blob/master/LICENSE)

Author
------

[](#author)

[stk2k](https://github.com/stk2k)

Disclaimer
----------

[](#disclaimer)

This software is no warranty.

We are not responsible for any results caused by the use of this software.

Please use the responsibility of the your self.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~141 days

Total

5

Last Release

1808d ago

PHP version history (2 changes)0.1.0PHP &gt;=7.1

0.2.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/955f3d564811dc5e1212c1a7a66bc4eb7e11ac166cc38600f244dc25f97d3ef4?d=identicon)[stk2k](/maintainers/stk2k)

---

Top Contributors

[![stk2k](https://avatars.githubusercontent.com/u/985640?v=4)](https://github.com/stk2k "stk2k (13 commits)")

---

Tags

phpcommand-linePHP7getoptarg parser

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stk2k-argparser/health.svg)

```
[![Health](https://phpackages.com/badges/stk2k-argparser/health.svg)](https://phpackages.com/packages/stk2k-argparser)
```

###  Alternatives

[nunomaduro/laravel-console-task

Laravel Console Task is a output method for your Laravel/Laravel Zero commands.

2582.1M11](/packages/nunomaduro-laravel-console-task)[splitbrain/php-cli

Easy command line scripts for PHP with opt parsing and color output. No dependencies

177817.2k28](/packages/splitbrain-php-cli)[aura/cli

Provides the equivalent of request (Context) and response (Stdio) classes for a command line environment, including Getopt support.

1051.6M29](/packages/aura-cli)[nunomaduro/laravel-console-summary

A Beautiful Laravel Console Summary for your Laravel/Laravel Zero commands.

662.0M3](/packages/nunomaduro-laravel-console-summary)[nunomaduro/laravel-console-dusk

Laravel Console Dusk allows the usage of Laravel Dusk in Laravel/Laravel Zero artisan commands.

16255.4k7](/packages/nunomaduro-laravel-console-dusk)[clue/commander

Finally a sane way to register available commands and arguments and match your command line in PHP.

16724.0k9](/packages/clue-commander)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
