PHPackages                             me-io/php-ini-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. me-io/php-ini-parser

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

me-io/php-ini-parser
====================

A Zend\_Config\_Ini like parser for .ini files.

1.0.2(8y ago)85211MITPHPPHP &gt;=7.0

Since Feb 15Pushed 7y ago5 watchersCompare

[ Source](https://github.com/me-io/php-ini-parser)[ Packagist](https://packagist.org/packages/me-io/php-ini-parser)[ RSS](/packages/me-io-php-ini-parser/feed)WikiDiscussions master Synced 3w ago

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

 PHP .ini parser
=================

[](#--php-ini-parser)

 Ini Parser is a simple parser for complex INI files, providing a number of extra syntactic features to the built-in INI parsing functions, including section inheritance, property nesting, and array literals.

---

[![Build Status](https://camo.githubusercontent.com/c426c565220456cab5f6fe7819080f7554660f1ba76e21c3d6b36722f798f411/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d652d696f2f7068702d696e692d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/me-io/php-ini-parser)[![Code Cov](https://camo.githubusercontent.com/1c35cf6346baa470f08c8ac0d585798b6a63289497ada9d39e46eef362f80a86/68747470733a2f2f636f6465636f762e696f2f67682f6d652d696f2f7068702d696e692d7061727365722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/me-io/php-ini-parser)[![Scrutinizer](https://camo.githubusercontent.com/1a6e42265d951c1705c41a41ea32be1fb89af76423cdeae53ab3bace18efe8e0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d652d696f2f7068702d696e692d7061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/me-io/php-ini-parser/?branch=master)[![downloads](https://camo.githubusercontent.com/c27389083d57b32b70f8fe5d740f34e0d0269dac00f6d55161c8cda4b6832508/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d652d696f2f7068702d696e692d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/me-io/php-ini-parser/stats)[![MIT License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/me-io/php-ini-parser/blob/master/LICENSE.md)[![Donate](https://camo.githubusercontent.com/21b9b3571c7f2fc583ad6b1b49aeb1524dd82f18a1b2e83c005c570cb71816ab/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d3137394244372e7376673f7374796c653d666c61742d73717561726573)](https://www.paypal.me/meabed)

[![All Contributors](https://camo.githubusercontent.com/db0a672758a6b3f2641e6c6099e3fadfd608167acfae3b31425eb3917b0dc47f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f616c6c5f636f6e7472696275746f72732d322d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](#contributors)[![PRs Welcome](https://camo.githubusercontent.com/25b3e6d0d42c98de74a98cbb4d149a1c09020cf6d1361993b72d7d5b8ffed363/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](http://makeapullrequest.com)[![Code of Conduct](https://camo.githubusercontent.com/6cf3a420df991efb9d5319bcf31f1aec6d12e660e25f13256cb256e76a4399a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f64652532306f662d636f6e647563742d6666363962342e7376673f7374796c653d666c61742d737175617265)](https://github.com/me-io/php-ini-parser/blob/master/CODE_OF_CONDUCT.md)[![Watch on GitHub](https://camo.githubusercontent.com/1f4291ea117de789ee7f77728531446a9d08bbd06bc21cd658fadc6be7d70df8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f6d652d696f2f7068702d696e692d7061727365722e7376673f7374796c653d736f6369616c)](https://github.com/me-io/php-ini-parser/watchers)[![Star on GitHub](https://camo.githubusercontent.com/cc60c96d2f855aa3c72eb01b2bef21d5ff51dbcf286ac23f0ea2745ab8ff5e9e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6d652d696f2f7068702d696e692d7061727365722e7376673f7374796c653d736f6369616c)](https://github.com/me-io/php-ini-parser/stargazers)[![Tweet](https://camo.githubusercontent.com/efef4788e7011a056f0a0e91544fa9658f1925c186919c2bdd29e53f168d1499/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f68747470732f6769746875622e636f6d2f6d652d696f2f7068702d696e692d7061727365722e7376673f7374796c653d736f6369616c)](https://twitter.com/intent/tweet?text=Check%20out%20php-ini-parser!%20https://github.com/me-io/php-ini-parser%20%F0%9F%91%8D)

Installing
----------

[](#installing)

Add `me-io/php-ini-parser` following inside your `composer.json` file like this:

```
{
    "require": {
        "me-io/php-ini-parser": "^1"
    }
}
```

Then inside your terminal run the following command to install the dependencies:

```
composer install
```

Example
-------

[](#example)

Standard INI files look like this:

```
key = value
another_key = another value

[section_name]
a_sub_key = yet another value
```

And when parsed with PHP's built-in `parse_ini_string()` or `parse_ini_file()`, looks like:

```
[
    'key' => 'value',
    'another_key' => 'another value',
    'section_name' => [
        'a_sub_key' => 'yet another value'
    ]
]
```

This is great when you just want a simple configuration file, but here is a super-charged INI file that you might find in the wild:

```
environment = testing

[testing]
debug = true
database.connection = "mysql:host=127.0.0.1"
database.name = test
database.username =
database.password =
secrets = [1,2,3]

[staging : testing]
database.name = stage
database.username = staging
database.password = 12345

[production : staging]
debug = false;
database.name = production
database.username = root
```

And when parsed with \\Ini\\Parser:

```
$parser = new \Ini\Parser('sample.ini');
$config = $parser->parse();
```

You get the following structure:

```
[
    'environment' => 'testing',
    'testing' => [
        'debug' => '1',
        'database' => [
            'connection' => 'mysql:host=127.0.0.1',
            'name' => 'test',
            'username' => '',
            'password' => ''
        ],
        'secrets' => ['1','2','3']
    ],
    'staging' => [
        'debug' => '1',
        'database' => [
            'connection' => 'mysql:host=127.0.0.1',
            'name' => 'stage',
            'username' => 'staging',
            'password' => '12345'
        ],
       'secrets' => ['1','2','3']
    ],
    'production' => [
        'debug' => '',
        'database' => [
            'connection' => 'mysql:host=127.0.0.1',
            'name' => 'production',
            'username' => 'root',
            'password' => '12345'
        ],
        'secrets' => ['1','2','3']
    ]
]
```

Supported Features
------------------

[](#supported-features)

### Array Literals

[](#array-literals)

You can directly create arrays using the syntax `[a, b, c]` on the right hand side of an assignment. For example:

```
colors = [blue, green, red]
```

**NOTE:** At the moment, quoted strings inside array literals have undefined behavior.

### Dictionaries and complex structures

[](#dictionaries-and-complex-structures)

Besides arrays, you can create dictionaries and more complex structures using JSON syntax. For example, you can use:

```
people = '{
    "boss": {
        "name": "John",
        "age": 42
    },
    "staff": [
        {
            "name": "Mark",
            "age": 35
        },
        {
            "name": "Bill",
            "age": 44
        }
    ]
}'
```

This turns into an array like:

```
[
    'boss' => [
        'name' => 'John',
        'age' => 42
    ],
    'staff' => [
        [
            'name' => 'Mark',
            'age' => 35,
        ],
        [
            'name' => 'Bill',
            'age' => 44,
        ],
    ],
]
```

> **NOTE:** Remember to wrap the JSON strings in single quotes for a correct analysis. The JSON names must be enclosed in double quotes and trailing commas are not allowed.

### Property Nesting

[](#property-nesting)

Ini Parser allows you to treat properties as associative arrays:

```
person.age = 42
person.name.first = John
person.name.last = Doe
```

This turns into an array like:

```
[
    'person' => [
        'age' => 42,
        'name' => [
            'first' => 'John',
            'last' => 'Doe'
        ]
    ]
]
```

### Section Inheritance

[](#section-inheritance)

Keeping to the DRY principle, Ini Parser allows you to "inherit" from other sections (similar to OOP inheritance), meaning you don't have to continually re-define the same properties over and over again. As you can see in the example above, "production" inherits from "staging", which in turn inherits from "testing".

You can even inherit from multiple parents, as in `[child : p1 : p2 : p3]`. The properties of each parent are merged into the child from left to right, so that the properties in `p1` are overridden by those in `p2`, then by `p3`, then by those in `child` on top of that.

During the inheritance process, if a key ends in a `+`, the merge behavior changes from overwriting the parent value to prepending the parent value (or appending the child value - same thing). So the example file

```
[parent]
arr = [a,b,c]
val = foo

[child : parent]
arr += [x,y,z]
val += bar
```

would be parsed into the following:

```
[
    'parent' => [
        'arr' => ['a','b','c'],
        'val' => 'foo'
    ],
    'child' => [
        'arr' => ['a','b','c','x','y','z'],
        'val' => 'foobar'
    ]
]
```

> *If you can think of a more useful operation than concatenation for non-array types, please open an issue*

Finally, it is possible to inherit from the special `^` section, representing the top-level or global properties:

```
foo = bar

[sect : ^]

```

Parses to:

```
[
    'foo' => 'bar',
    'sect' => [
        'foo' => 'bar'
    ]
]
```

### ArrayObject

[](#arrayobject)

As an added bonus, Ini Parser also allows you to access the values OO-style:

```
echo $config->production->database->connection; // output: mysql:host=127.0.0.1
echo $config->staging->debug; // output: 1
```

Contributors
------------

[](#contributors)

A huge thanks to all of our contributors:

[![](https://avatars0.githubusercontent.com/u/45731?v=3)
**Mohamed Meabed**](https://github.com/Meabed)
[💻](https://github.com//php-ini-parser/commits?author=Meabed "Code") [📢](#talk-Meabed "Talks")[![](https://avatars2.githubusercontent.com/u/16267321?v=3)
**Zeeshan Ahmad**](https://github.com/ziishaned)
[💻](https://github.com//php-ini-parser/commits?author=ziishaned "Code") [🐛](https://github.com//php-ini-parser/issues?q=author%3Aziishaned "Bug reports") [⚠️](https://github.com//php-ini-parser/commits?author=ziishaned "Tests") [📖](https://github.com//php-ini-parser/commits?author=ziishaned "Documentation")License
-------

[](#license)

The code is available under the [MIT license](LICENSE.md).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

3

Last Release

2961d ago

### Community

Maintainers

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

---

Top Contributors

[![till](https://avatars.githubusercontent.com/u/27003?v=4)](https://github.com/till "till (42 commits)")[![austinhyde](https://avatars.githubusercontent.com/u/694995?v=4)](https://github.com/austinhyde "austinhyde (36 commits)")[![nilbuild](https://avatars.githubusercontent.com/u/4921183?v=4)](https://github.com/nilbuild "nilbuild (19 commits)")[![meabed](https://avatars.githubusercontent.com/u/45731?v=4)](https://github.com/meabed "meabed (19 commits)")[![javiermarinros](https://avatars.githubusercontent.com/u/840412?v=4)](https://github.com/javiermarinros "javiermarinros (16 commits)")[![ziishaned](https://avatars.githubusercontent.com/u/16267321?v=4)](https://github.com/ziishaned "ziishaned (12 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")[![fredpe](https://avatars.githubusercontent.com/u/1382320?v=4)](https://github.com/fredpe "fredpe (1 commits)")

---

Tags

iniiniparserphp-configurationphp-iniphp-parserconfigurationini

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/me-io-php-ini-parser/health.svg)

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

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k514.6M1.9k](/packages/symfony-options-resolver)[league/config

Define configuration arrays with strict schemas and access values with dot notation

565323.7M35](/packages/league-config)[josegonzalez/dotenv

dotenv file parsing for PHP

27810.2M156](/packages/josegonzalez-dotenv)[chillerlan/php-settings-container

A container class for immutable settings objects. Not a DI container.

3432.2M22](/packages/chillerlan-php-settings-container)

PHPackages © 2026

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