PHPackages                             retrinko/ini - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. retrinko/ini

ActiveLibrary[File &amp; Storage](/categories/file-storage)

retrinko/ini
============

Library for parsing and writing INI files

v2.1.0(3y ago)1067.0k↓27.5%2[1 issues](https://github.com/retrinko/ini/issues)[1 PRs](https://github.com/retrinko/ini/pulls)2MITPHPPHP &gt;=7.4.0CI failing

Since May 8Pushed 3y agoCompare

[ Source](https://github.com/retrinko/ini)[ Packagist](https://packagist.org/packages/retrinko/ini)[ RSS](/packages/retrinko-ini/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (2)

[![Build Status](https://camo.githubusercontent.com/7e975b9ccfa6067016a43b527737658e064910c888c66a0b776b785f8a695e92/68747470733a2f2f7472617669732d63692e6f72672f72657472696e6b6f2f696e692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/retrinko/ini)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/454c774a1f63a2177f83ba038546378dbd2eef18b881d5eb0a5e1726e72ca6f1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72657472696e6b6f2f696e692f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/retrinko/ini/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/456bb592b402828854ed540b44dc7cf0daa5ec847c912652ff43c29124a92e14/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f72657472696e6b6f2f696e692f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/retrinko/ini/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/d08075136a74f870525740f6cdcc5908c64d200656cefbec7a4e2b5089ce3be3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72657472696e6b6f2f696e692e737667)](https://packagist.org/packages/retrinko/ini)

retrinko/ini
============

[](#retrinkoini)

Library for parsing and writing ini files.

Features provided over native PHP ini parser:

- Throws exceptions instead of PHP errors.
- Better type support.
- Section inheritance.

*NOTE*: This parser does not allow orphan items (items defined outside a section).

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

[](#installation)

Install the latest version with

```
$ composer require retrinko/ini

```

Basic usage
-----------

[](#basic-usage)

### Reading ini contents:

[](#reading-ini-contents)

**NOTICE!!**: Attention to **.local.ini** files. If you try to load a file named *\[whateverYouWants\].ini* and *\[whateverYouWants\].local.ini* file exists in the same path, the contents of the two files will be merged. If the same key is defined in both files, the one defined in *\[whateverYouWants\].local.ini* will override the value defined in *\[whateverYouWants\].ini*.

Ini file contents (sample.ini):

```
[default]
key1 = default value1
key2 = default value2

; A section inherits default section
[A : default]
key1 = A value1 ; overrides default section key1 item
key3 = A value3 ; add new item

; B section inherits A section
[B : A]
key1 = B value1 ; overrides A section key1 item
key3 = B value3 ; overrides A section key3 item
; Simple array
A[] = a
A[] = b
; Assoc. array
B[one] = 1
B[two] = 2
; Bool values
boolTrue = true
boolFalse = false
boolYes = yes
boolNo = no
boolOn = on
boolOff = off
boolNone = none
intVal = 3
floatVal = 5.7

```

PHP sample code for reading ini file (sample.ini):

```
use Retrinko\Ini\IniFile;

try
{
    // Load ini file
    $iniFile = IniFile::load((__DIR__ . '/sample.ini'));

    // Read "key1" value from "default" section
    $key1 = $iniFile->get('default', 'key1');

    // Read "key1" value from "A" section
    $key1 = $iniFile->get('A', 'key1');

    // Read "key1" value from "B" section
    $key1 = $iniFile->get('B', 'key1');

    // Read "boolYes" value from "B" section
    $boolYes = $iniFile->get('B', 'boolYes');

    // Get ini file contents as array
    $array = $iniFile->toArray();
}
catch (\Exception $e)
{
    printf('Exception! %s'.PHP_EOL, $e->getMessage());
}

```

### Writing ini contents:

[](#writing-ini-contents)

PHP sample code for writing ini file:

```
use Retrinko\Ini\IniFile;
use Retrinko\Ini\IniSection;

try
{
    // Create new IniFile instance
    $iniFile = new IniFile();

    // Create section "base"
    $section = new IniSection('base');
    // Add items to section "base"
    $section->set('hello', 'world');
    $section->set('colors', ['red', 'green']);
    $section->set('rgb', ['red'=>'AA0000', 'green'=>'00AA00']);
    $section->set('width', 25);
    $section->set('height', 50.33);
    $section->set('bool', true);
    $section->set('nullValue', null);
    // Add section "base" to ini file
    $iniFile->addSection($section);

    // Add child section "child"
    $childSection = new IniSection('child', $section);
    // Add items to section "child"
    $childSection->set('height', 20);
    $childSection->set('width', 20);
    // Add section "child" to ini file
    $iniFile->addSection($childSection);

    // Add item values to sections
    $iniFile->set('base', 'new-item', 'value');
    $iniFile->set('child', 'last-item', 'last');

    // Save to file
    $iniFile->save(__DIR__.'/test.ini');

}
catch (\Exception $e)
{
    printf('Exception! %s'.PHP_EOL, $e->getMessage());
}

```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

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

Recently: every ~608 days

Total

9

Last Release

1215d ago

Major Versions

v0.5 → v1.0.02016-07-08

v1.0.0 → v2.0.02016-07-08

PHP version history (3 changes)v0.1PHP &gt;=5.4.0

v2.0.1PHP &gt;=5.6.0

v2.1.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17164968?v=4)[Miguel A. Graña](/maintainers/retrinko)[@retrinko](https://github.com/retrinko)

---

Top Contributors

[![retrinko](https://avatars.githubusercontent.com/u/17164968?v=4)](https://github.com/retrinko "retrinko (43 commits)")

---

Tags

fileparsereadwriteini

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/retrinko-ini/health.svg)

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

###  Alternatives

[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.7k285.7M1.0k](/packages/league-flysystem-aws-s3-v3)[adlawson/vfs

Virtual file system

300440.8k22](/packages/adlawson-vfs)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8737.3M276](/packages/league-flysystem-memory)[magicalex/write-ini-file

Write-ini-file php library for create, remove, erase, add, and update ini file

18160.9k5](/packages/magicalex-write-ini-file)[league/flysystem-sftp-v3

SFTP filesystem adapter for Flysystem.

6134.8M156](/packages/league-flysystem-sftp-v3)[league/flysystem-async-aws-s3

AsyncAws S3 filesystem adapter for Flysystem.

2812.1M44](/packages/league-flysystem-async-aws-s3)

PHPackages © 2026

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