PHPackages                             zzengineer/getoptc - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. zzengineer/getoptc

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

zzengineer/getoptc
==================

C style getopt for php

0.5(10y ago)118MITPHPPHP &gt;=5.3.0

Since Sep 18Pushed 10y ago1 watchersCompare

[ Source](https://github.com/zzengineer/getoptc)[ Packagist](https://packagist.org/packages/zzengineer/getoptc)[ RSS](/packages/zzengineer-getoptc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (3)Used By (0)

getoptc
=======

[](#getoptc)

C style getopt for php

[![Latest Stable Version](https://camo.githubusercontent.com/e38bad8ebc8ed5e038e784092d373d5826c6c206a977a491e36f10b22404df06/68747470733a2f2f706f7365722e707567782e6f72672f7a7a656e67696e6565722f6765746f7074632f762f737461626c65)](https://packagist.org/packages/zzengineer/getoptc) [![Total Downloads](https://camo.githubusercontent.com/9c798dae63f18038d15b8292614c0234c948a7084899a24c42013d50fdc9d989/68747470733a2f2f706f7365722e707567782e6f72672f7a7a656e67696e6565722f6765746f7074632f646f776e6c6f616473)](https://packagist.org/packages/zzengineer/getoptc) [![Latest Unstable Version](https://camo.githubusercontent.com/466717104ca3f10b8620c469294b47bd629a6ace57a2c3b8c7860fa4af37adbe/68747470733a2f2f706f7365722e707567782e6f72672f7a7a656e67696e6565722f6765746f7074632f762f756e737461626c65)](https://packagist.org/packages/zzengineer/getoptc) [![License](https://camo.githubusercontent.com/a1a9df5bcf5167f40385c4a3ca5e1af195a014888b750b8f4e5553fa73cd8c27/68747470733a2f2f706f7365722e707567782e6f72672f7a7a656e67696e6565722f6765746f7074632f6c6963656e7365)](http://opensource.org/licenses/MIT)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#---)

### NAME

[](#name)

getoptc -- get option character from command line argument list

### SYNOPSIS

[](#synopsis)

`function getoptc($args, $optstring, &$optind, &$optarg, $opterr = true)`

### DESCRIPTION

[](#description)

The **getoptc()** function parses a given command line argument list and returns the next known option character. An option character is *known* if it has been specified in the string of accepted option characters, `$optstring`.

The option string may contain the following elements: individual characters, and characters followed by a colon to indiacte an option argument is to follow. If an individual character is followed by two colons, then the option argument is optional; `$optarg` is set to the rest of the current word. It does not matter to **getoptc()** if a following argument has leading whitespace.

On return from **getoptc()**, `$optarg` is set to an argument if it is anticipated or `NULL` instead. `$optind` contains the index to the next list argument for a subsequent call to ***getoptc()***.

The variable `$optind` is initialized to 1. The `$optind` variable may be set to another value before a set of calls to **getoptc()** in order to skip over more or less list entries.

The variable `$opterr` is intialized to true, and can be disabled to surpress error messages. *see RETURN VALUES*

### RETURN VALUES

[](#return-values)

The **getoptc()** function returns the next kown option character in `$optstring`. If **getopt()** encounters a character not found in `$optstring` or if it detects a missing option argument, it returns `?` (question mark). If `$optstring` has a leading `:` then a missing optin argument causes `:` to be returned instead of `?`. In either case, the variable `$optarg` is set to the character that caused the error. The **getoptc()** function returns `false` when the argument list is exhausted. `$optind` will contain the index of the first non-option argument. Every subsequent call to **getoptc()** will return `false` and leave `$optind` and `$optarg` untouched.

### EXAMPLES

[](#examples)

```
while (($c =  getoptc($argv,'ab:c::', $optind, $optarg)) !== false)
  switch ($c) {
  case 'a': $flag_a=true; break;
  case 'b': $arg_b=$optarg; break;
  case 'c': $flag_c=true; $arg_c=$optarg; break;
  case '?':
  case ':':
  default : usage(); exit(1);
  }

for ($i = $optind; $i < count($argv); $i++)
   print "programm argument ". $argv[$i]. PHP_EOL;
```

### DIAGNOSTICS

[](#diagnostics)

If the **getoptc()** function encounters a character not found in the string `$optstring` or detects a missing option argument it writes an error messages to `STDERR`. Setting `$opterr` to `false` will disable these error messages.

Option arguments are allowed to begin with `-`; this is reasonable but reduces the amount of error checking possible.

### MISC

[](#misc)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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 ~3 days

Total

2

Last Release

3892d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f820dc12284096193f87228fd138fa5087e785a7453b1b4ad3e20f37d00d7f5?d=identicon)[zzengineer](/maintainers/zzengineer)

---

Top Contributors

[![zzengineer](https://avatars.githubusercontent.com/u/7922582?v=4)](https://github.com/zzengineer "zzengineer (26 commits)")

---

Tags

getopt

### Embed Badge

![Health badge](/badges/zzengineer-getoptc/health.svg)

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

###  Alternatives

[drupal/console-extend-plugin

Drupal Console Extend Plugin

13214.3M5](/packages/drupal-console-extend-plugin)[jjgrainger/posttypes

Simple WordPress custom post types.

382568.8k12](/packages/jjgrainger-posttypes)[league/glide-laravel

Glide adapter for Laravel

1433.2M35](/packages/league-glide-laravel)[nacmartin/phpexecjs

Run JavaScript code from PHP

1511.3M4](/packages/nacmartin-phpexecjs)[chriskonnertz/open-graph

Class that assists in building Open Graph meta tags

117428.6k3](/packages/chriskonnertz-open-graph)[jeremykenedy/slack-laravel

Laravel integration for the jeremykenedy/slack package, including facades and service providers.

54738.8k](/packages/jeremykenedy-slack-laravel)

PHPackages © 2026

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