PHPackages                             austinhyde/iniparser - 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. austinhyde/iniparser

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

austinhyde/iniparser
====================

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

v1.0.0-beta(13y ago)6845.5k↓50%27[2 PRs](https://github.com/austinhyde/IniParser/pulls)1MITPHP

Since Jan 5Pushed 5y ago8 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (1)

IniParser
=========

[](#iniparser)

[![Build Status](https://camo.githubusercontent.com/358022d329244eaca6aae985ccc35ed83f88db1e49826458e9ae9387c4abd26f/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f61757374696e687964652f496e695061727365722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/austinhyde/IniParser)

IniParser 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.

**IMPORTANT:** IniParser should be considered beta-quality, and there may still be bugs. Feel free to open an issue or submit a pull request, and I'll take a look at it!

Installing by [Composer](https://getcomposer.org)
-------------------------------------------------

[](#installing-by-composer)

Set your `composer.json` file to have :

```
{
	"require": {
		"austinhyde/iniparser": "dev-master"
	}
}
```

Then install the dependencies :

```
composer install
```

An Example
----------

[](#an-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

```
array(
    'key' => 'value',
    'another_key' => 'another value',
    'section_name' => array(
        '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 IniParser:

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

```

You get the following structure:

```
array(
    'environment' => 'testing',
    'testing' => array(
        'debug' => '1',
        'database' => array(
            'connection' => 'mysql:host=127.0.0.1',
            'name' => 'test',
            'username' => '',
            'password' => ''
        ),
        'secrets' => array('1','2','3')
    ),
    'staging' => array(
        'debug' => '1',
        'database' => array(
            'connection' => 'mysql:host=127.0.0.1',
            'name' => 'stage',
            'username' => 'staging',
            'password' => '12345'
        ),
       'secrets' => array('1','2','3')
    ),
    'production' => array(
        'debug' => '',
        'database' => array(
            'connection' => 'mysql:host=127.0.0.1',
            'name' => 'production',
            'username' => 'root',
            'password' => '12345'
        ),
        'secrets' => array('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:

```
array(
    'boss' => array(
        'name' => 'John',
        'age' => 42
    ),
    'staff' => array(
        array (
            'name' => 'Mark',
            'age' => 35,
        ),
        array (
            '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)

IniParser 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:

```
array (
    'person' => array (
        'age' => 42,
        'name' => array (
            'first' => 'John',
            'last' => 'Doe'
        )
    )
)
```

### Section Inheritance

[](#section-inheritance)

Keeping to the DRY principle, IniParser 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:

```
array(
    'parent' => array(
        'arr' => array('a','b','c'),
        'val' => 'foo'
    ),
    'child' => array(
        'arr' => array('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:

```
array (
    'foo' => 'bar',
    'sect' => array (
        'foo' => 'bar'
    )
)
```

### ArrayObject

[](#arrayobject)

As an added bonus, IniParser 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
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4875d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c221166d547b835ed6aa280ffc6a4397686c787257bc01652a474202ccc7c9c?d=identicon)[austinhyde](/maintainers/austinhyde)

---

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)")[![javiermarinros](https://avatars.githubusercontent.com/u/840412?v=4)](https://github.com/javiermarinros "javiermarinros (16 commits)")[![fredpe](https://avatars.githubusercontent.com/u/1382320?v=4)](https://github.com/fredpe "fredpe (1 commits)")

---

Tags

configuration

### Embed Badge

![Health badge](/badges/austinhyde-iniparser/health.svg)

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

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

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

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

564302.2M24](/packages/league-config)[josegonzalez/dotenv

dotenv file parsing for PHP

2799.8M137](/packages/josegonzalez-dotenv)[dflydev/dot-access-configuration

Given a deep data structure representing a configuration, access configuration by dot notation.

13414.5M4](/packages/dflydev-dot-access-configuration)[symfony/requirements-checker

Check Symfony requirements and give recommendations

2014.7M29](/packages/symfony-requirements-checker)[chillerlan/php-settings-container

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

3427.3M21](/packages/chillerlan-php-settings-container)

PHPackages © 2026

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