PHPackages                             martinsik/php-doc-parser - 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. martinsik/php-doc-parser

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

martinsik/php-doc-parser
========================

Parser for PHP documentation with CLI interface and output to JSON + Markdown.

2.0.2(10y ago)3911317[1 PRs](https://github.com/martinsik/php-doc-parser/pulls)MITHTMLPHP &gt;=5.4

Since May 13Pushed 8y ago4 watchersCompare

[ Source](https://github.com/martinsik/php-doc-parser)[ Packagist](https://packagist.org/packages/martinsik/php-doc-parser)[ Docs](https://github.com/martinsik/php-doc-parser)[ RSS](/packages/martinsik-php-doc-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

PHP Documentation Parser
========================

[](#php-documentation-parser)

[![Build Status](https://camo.githubusercontent.com/a0821bdd3dbe0d2d14f8ee205551d2a675128f4adc3ddf7dc3a93f104df93b61/68747470733a2f2f7472617669732d63692e6f72672f6d617274696e73696b2f7068702d646f632d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/martinsik/php-doc-parser)

This package downloads gziped documentation from php.net, parses it and outputs all found functions as JSON with Markdown syntax. It comes with CLI interface for comfortable usage.

[![](https://raw.githubusercontent.com/martinsik/php-doc-parser/master/doc/animation.gif)](https://raw.githubusercontent.com/martinsik/php-doc-parser/master/doc/animation.gif)

Installation
------------

[](#installation)

Add `martinsik/php-doc-parser` to your `composer.json` dependencies:

```
"require": {
    ...
    "martinsik/php-doc-parser": "~2.0"
}

```

Then run `composer.phar install`.

Usage
-----

[](#usage)

### As a CLI script

[](#as-a-cli-script)

Composer adds `doc-parser` file to your directory with binaries (`vendor/bin` by default). Run it and follow the instructions on the screen.

```
$ vendor/bin/doc-parser

```

Results are saved into `output` directory by default. This creates following files (names are generated by selected language and mirror):

- `en_php_net.json` - Very large associative array with all parsed functions and their data. See [sample output bellow](https://github.com/martinsik/php-doc-parser#sample-output).
- `en_php_net.list.json` - List of all function names in lowercase.
- `en_php_net.examples.json` (optional) - If you chose to export examples it'll put them into a separate file.

For full list of options run:

```
$ vendor/bin/doc-parser help parser:run

```

### As a 3rd party package

[](#as-a-3rd-party-package)

Create an instance of `DocParser\Package` class to set language and mirror you want to parse and it'll download and unpack the documentation for you. Then give the `DocParser\Parser` directory with files you want to parse and it'll return a `DocParser\ParserResult` object with all data as arrays.

```
use DocParser\Package;
use DocParser\Parser;

$package = new Package('en', 'php.net');
$tmpFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $package->getOrigFilename();
$package->download($tmpFile);
$unpackedDir = $package->unpack();

$result = $parser->processDir($unpackedDir, Parser::EXPORT_EXAMPLES);
// you can parse just a single file with: $parser->processFile('file.html');

foreach ($result->getResult() as $funcName => $funcData) {
    // Note that all function names used as keys are lowercase.
    // Proper function names are in parameter lists (see [sample bellow](https://github.com/martinsik/php-doc-parser#sample-output)).
    // eg.: $funcData['params'][0]['name']

    // Get all examples for this function.
    // $result->getExamples($funcName);

    // If you used Parser::IMPORT_EXAMPLES then examples are right in $funcData.
    // With Parser::SKIP_EXAMPLES they're not parsed at all.
}

// Remove all temporary files
$package->cleanup();
```

Sample output
-------------

[](#sample-output)

This is what `DateTime::setDate` looks like deep inside `en_php_net.json`.

```
{
    "abs": { ... },
    "array_pop": { ... },
    ...
    "datetime::add": { ... },
    "datetime::setdate": {
        "desc": "Sets the date.",
        "long_desc": "Resets the current date of the DateTime object to a different date.",
        "ver": "PHP 5 >= 5.2.0",
        "ret_desc": "Returns the DateTime object for method chaining or FALSE on failure.",
        "seealso": [
            "DateTime::setISODate",
            "DateTime::setTime"
        ],
        "filename": "datetime.setdate",
        "params": [
            {
                "list": [
                    {
                        "type": "int",
                        "var": "$year",
                        "beh": "required",
                        "desc": "Year of the date."
                    },
                    {
                        "type": "int",
                        "var": "$month",
                        "beh": "required",
                        "desc": "Month of the date."
                    },
                    {
                        "type": "int",
                        "var": "$day",
                        "beh": "required",
                        "desc": "Day of the date."
                    }
                ],
                "name": "DateTime::setDate",
                "ret_type": "DateTime"
            },
            {
                "list": [
                    {
                        "type": "DateTime",
                        "var": "$object",
                        "beh": "required",
                        "desc": "Procedural style only: A DateTime object returned by date\\_create(). The function modifies this object."
                    },
                    {
                        "type": "int",
                        "var": "$year",
                        "beh": "required",
                        "desc": "Year of the date."
                    },
                    {
                        "type": "int",
                        "var": "$month",
                        "beh": "required",
                        "desc": "Month of the date."
                    },
                    {
                        "type": "int",
                        "var": "$day",
                        "beh": "required",
                        "desc": "Day of the date."
                    }
                ],
                "name": "date_date_set",
                "ret_type": "DateTime"
            }
        ],
        "examples": [
            {
                "title": "DateTime::setDate() example",
                "source": "$date = new DateTime();\n$date->setDate(2001, 2, 3);\necho $date->format('Y-m-d');",
                "output": "2001-02-03"
            },
            {
                "title": "Values exceeding ranges are added to their parent values",
                "source": "$date = new DateTime();\n\n$date->setDate(2001, 2, 28);\necho $date->format('Y-m-d') . \"\\n\";\n\n$date->setDate(2001, 2, 29);\necho $date->format('Y-m-d') . \"\\n\";\n\n$date->setDate(2001, 14, 3);\necho $date->format('Y-m-d') . \"\\n\";",
                "output": "2001-02-28\n2001-03-01\n2002-02-03"
            }
        ]
    },
    "date_date_set": "DateTime::setDate",
    "datedime::createfromformat": { ... },
    "date_create_from_format": "DateTime::createFromFormat",
    ...
    "strpos": { ... }
    "tempnam": { ... }
    ...
}

```

Note that this function has two different definitions, `DateTime::setDate` and `date_date_set`, where each takes different parameters. In order to be able to search both functions there are two keys for this function, where the second key, `date_date_set`, is just a reference to the first one. Also, all keys are lowercase.

Why?
----

[](#why)

I use this script to generate "database" for my Google Chrome Extension called [PHP Ninja Manual](https://chrome.google.com/webstore/detail/clbhjjdhmgeibgdccjfoliooccomjcab "PHP Ninja Manual").

By the way there's an official [PHP Documentation generator](https://wiki.php.net/doc/articles/phd_ide) for IDEs, but when I started developing my extension it didn't exist. I don't know what are its capabilities now but maybe it's worth a try.

Known limitations
-----------------

[](#known-limitations)

- There are no PHP statements (for, if, while, ...)
- It's not able to recognize objective or procedural style in classes like in `mysqli`.

Testing
-------

[](#testing)

This package uses [Behat](https://github.com/Behat/Behat) for testing. Run tests with:

```
$ bin/behat

```

License
-------

[](#license)

PHP Documentation Parser (this package) is licensed under MIT license.

PHP Documentation pages ([php.net/docs.php](http://php.net/docs.php)) are licensed under [Creative Commons Attribution 3.0 License](http://creativecommons.org/licenses/by/3.0/legalcode).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

3

Last Release

3837d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8637aa5ca3cabae8b692c040dd7edbbacf6fae82f92e6e05dc35ab3c52efa38?d=identicon)[martinsik](/maintainers/martinsik)

---

Top Contributors

[![martinsik](https://avatars.githubusercontent.com/u/238765?v=4)](https://github.com/martinsik "martinsik (11 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/martinsik-php-doc-parser/health.svg)

```
[![Health](https://phpackages.com/badges/martinsik-php-doc-parser/health.svg)](https://phpackages.com/packages/martinsik-php-doc-parser)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[ramsey/conventional-commits

A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook action!

1931.2M122](/packages/ramsey-conventional-commits)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)

PHPackages © 2026

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