PHPackages                             rik72/inifile - 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. rik72/inifile

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

rik72/inifile
=============

classes to read and modify ini files by preserving comments and empty lines

v3.3.6(5y ago)0194LGPL-2.1PHPPHP &gt;=5.6.1

Since Jun 1Pushed 5y agoCompare

[ Source](https://github.com/rik72/inifile)[ Packagist](https://packagist.org/packages/rik72/inifile)[ Docs](https://github.com/rik72/inifile)[ RSS](/packages/rik72-inifile/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (29)Used By (0)

Some classes to read and modify ini files by preserving comments, empty lines.

They supports sections and array values. You can also merge sections, merge two ini files, and rename some values or sections.

installation
============

[](#installation)

You can install it from Composer. In your project:

```
composer require "jelix/inifile"

```

Usage
=====

[](#usage)

The `\Jelix\IniFile\IniModifier` class allows to read an ini file, to modify its content including comments, and save it by preserving empty lines.

Don't use this class to just read content. Use instead `\Jelix\IniFile\Util` or `parse_ini_file()` for this purpose, it's more efficient and performant.

```
$ini = new \Jelix\IniFile\IniModifier('myfile.ini');

// setting a parameter.  (section_name is optional)
$ini->setValue('parameter_name', 'value', 'section_name');

// retrieve a parameter value. (section_name is optional)
$val = $ini->getValue('parameter_name', 'section_name');

// remove a parameter
$ini->removeValue('parameter_name', 'section_name');

// setting a comment (in the line preceding the parameter) - the leading ';'
// can be omitted or included in the comment line, if missing will be added
$ini->setComments('parameter_name', '; single-line comment text', 'section_name');

// setting a multi-line comment (in the lines preceding the parameter)
$ini->setComments('parameter_name', [ 'first line', 'second line' ], 'section_name');

// remove all comment lines preceding a parameter
$ini->removeComments('parameter_name', 'section_name');

// save into file
$ini->save();
$ini->saveAs('otherfile.ini');

// importing an ini file into an other
$ini2 = new \Jelix\IniFile\IniModifier('myfile2.ini');
$ini->import($ini2);
$ini->save();

// merging two section: merge sectionSource into sectionTarget and then
// sectionSource is removed
$ini->mergeSection('sectionSource', 'sectionTarget');
```

It support parsing of parameter values into PHP types (string, numeric, boolean) as well as

It supports also array values (indexed or associative) like :

```
foo[]=bar
foo[]=baz
assoc[key1]=car
assoc[otherkey]=bus

```

Then in PHP:

```
$ini = new \Jelix\IniFile\IniModifier('myfile.ini');

$val = $ini->getValue('foo'); // array('bar', 'baz');
$val = $ini->getValue('assoc'); // array('key1'=>'car', 'otherkey'=>'bus');

$ini->setValue('foo', 'other value', 0, '');
$val = $ini->getValue('foo'); // array('bar', 'baz', 'other value');

$ini->setValue('foo', 'five', 0, 5);
$val = $ini->getValue('foo'); // array('bar', 'baz', 'other value', 5 => 'five');

$ini->setValue('assoc', 'other value', 0, 'ov');
$val = $ini->getValue('assoc'); // array('key1'=>'car', 'otherkey'=>'bus', 'ov'=>'other value');
```

After saving, the ini content is:

```
foo[]=bar
foo[]=baz
assoc[key1]=car
assoc[otherkey]=bus

foo[]="other value"
foo[]=five
assoc[ov]="other value"
```

Note: the result can be parsed by `parse_ini_file()`.

See the class to learn about other methods and options.

The `\Jelix\IniFile\MultiIniModifier` allows to load two ini files at the same time, where the second one "overrides" values of the first one.

The `\Jelix\IniFile\IniModifierArray` allows to load several files at the same time, and to manage their values as if files were merged.

The `\Jelix\IniFile\Util` contains simple methods to read, write and merge ini files. These are just wrappers around `parse_ini_file()`.

###  Health Score

30

—

LowBetter than 67% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% 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 ~81 days

Recently: every ~1 days

Total

27

Last Release

1835d ago

Major Versions

v1.7.1 → v2.0.02016-11-29

v2.5.0 → v3.0.02018-10-24

PHP version history (3 changes)v1.7.0PHP &gt;=5.3.3

v2.1.0PHP &gt;=5.6.0

v3.2.0PHP &gt;=5.6.1

### Community

Maintainers

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

---

Top Contributors

[![laurentj](https://avatars.githubusercontent.com/u/336034?v=4)](https://github.com/laurentj "laurentj (54 commits)")[![julieni](https://avatars.githubusercontent.com/u/995738?v=4)](https://github.com/julieni "julieni (1 commits)")[![rik72](https://avatars.githubusercontent.com/u/4755775?v=4)](https://github.com/rik72 "rik72 (1 commits)")

---

Tags

filesini

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rik72-inifile/health.svg)

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

###  Alternatives

[lorisleiva/lody

Load files and classes as lazy collections in Laravel.

956.2M6](/packages/lorisleiva-lody)[jbzoo/data

An extended version of the ArrayObject object for working with system settings or just for working with data arrays

891.6M22](/packages/jbzoo-data)[wapmorgan/file-type-detector

Detects file type by filename or content and generates correct mimetype.

35364.7k2](/packages/wapmorgan-file-type-detector)[colinodell/indentation

Library to detect and manipulate indentation in strings and files

3910.8k3](/packages/colinodell-indentation)

PHPackages © 2026

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