PHPackages                             battye/php-array-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. battye/php-array-parser

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

battye/php-array-parser
=======================

Parse text representation of a PHP array into an actual PHP array.

v1.0.10(4y ago)43.8k↓54.5%11MITPHPPHP &gt;=5.3.3

Since Jan 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/battye/php-array-parser)[ Packagist](https://packagist.org/packages/battye/php-array-parser)[ RSS](/packages/battye-php-array-parser/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (13)Used By (1)

PHP Array Parser
================

[](#php-array-parser)

A small library to parse text representations of a PHP array and return an actual PHP array.

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

[](#installation)

Run `composer install` to run this script (and tests) in a standalone way. Alternatively, this can be used as a dependency in another project by running `composer require battye/php-array-parser "~1.0"`.

Reference the namespace at the top of your PHP files to utilise the included classes:

```
use battye\array_parser\parser;
use battye\array_parser\tokens;
```

If you notice any bugs, please raise an issue or pull request.

Example
-------

[](#example)

In both of the following examples, `$result` would contain a PHP array containing the representation of the string or text file provided.

### Raw String

[](#raw-string)

To parse a simple array is very easy:

```
$value = "array(0 => array('one' => 1, 'two' => 'two'));";
$result = parser::parse_simple($value);
```

In this case, `$result` would produce the following:

```
array(1) {
  [0] =>
  array(2) {
    'one' =>
    int(1)
    'two' =>
    string(3) "two"
  }
}

```

### Regex

[](#regex)

Regular expressions can also be used to parse complex files and extract array values:

```
$regex = '/\$lang\s+=\s+array_merge\(\$lang, array\((.*?)\)\);/s';
$file = __DIR__ . '/files/test_lang.php';
$result = parser::parse_regex($regex, $file);
```

Tests
-----

[](#tests)

[![Latest Stable Version](https://camo.githubusercontent.com/7af7c059f0a19dd9594a64b57e0d0de69176ab44b9a6c42ae4c43ea80b3cc47a/68747470733a2f2f706f7365722e707567782e6f72672f6261747479652f7068702d61727261792d7061727365722f762f737461626c65)](https://packagist.org/packages/battye/php-array-parser) [![Total Downloads](https://camo.githubusercontent.com/6c1baabb8b1bf686e86a4100faac641d39534ff3a9193d19e10d46bd61958a8b/68747470733a2f2f706f7365722e707567782e6f72672f6261747479652f7068702d61727261792d7061727365722f646f776e6c6f616473)](https://packagist.org/packages/battye/php-array-parser) [![GitHub Actions CI](https://github.com/battye/php-array-parser/actions/workflows/phpunit.yaml/badge.svg?branch=master)](https://github.com/battye/php-array-parser/actions/workflows/phpunit.yaml/badge.svg?branch=master)

The unit tests provide good examples of how to utilise this library and can be found in the `tests/` directory. To execute the unit tests, run:

```
vendor/bin/simple-phpunit tests/

```

###  Health Score

33

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity62

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

Recently: every ~231 days

Total

11

Last Release

1585d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b9ce1e69218256bc4ba5f74f39ecac1548761472e323898c5622170af7d6b49?d=identicon)[battye](/maintainers/battye)

---

Top Contributors

[![battye](https://avatars.githubusercontent.com/u/2110222?v=4)](https://github.com/battye "battye (18 commits)")

---

Tags

arrayparserphpphparrayparser

### Embed Badge

![Health badge](/badges/battye-php-array-parser/health.svg)

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

###  Alternatives

[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.3k2](/packages/zakirullin-mess)

PHPackages © 2026

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