2017 © Pedro Peláez
 

library inifile

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

image

jelix/inifile

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

  • Monday, February 12, 2018
  • by laurentj
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,769 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 12 Versions
  • 8 % Grown

The README.md

Some classes to read and modify ini files by preserving comments, empty lines., (*1)

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

installation

You can install it from Composer. In your project:, (*3)

composer require "jelix/inifile"

Usage

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

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., (*5)

$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');


// 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 supports also array values (indexed or associative) like :, (*6)

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

Then in PHP:, (*7)

$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:, (*8)

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()., (*9)

See the class to learn about other methods and options., (*10)

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

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

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

The Versions

12/02 2018

dev-master

9999999-dev http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.6.0

 

The Development Requires

ini files

12/02 2018

v2.4.2

2.4.2.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.6.0

 

The Development Requires

ini files

02/05 2017

v2.4.1

2.4.1.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.6.0

 

The Development Requires

ini files

30/04 2017

v2.4.0

2.4.0.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.6.0

 

The Development Requires

ini files

19/04 2017

v2.3.0

2.3.0.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.6.0

 

The Development Requires

ini files

10/02 2017

v2.2.1

2.2.1.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.6.0

 

The Development Requires

ini files

01/12 2016

v2.2.0

2.2.0.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.6.0

 

The Development Requires

ini files

30/11 2016

v2.1.0

2.1.0.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.6.0

 

The Development Requires

ini files

29/11 2016

v2.0.0

2.0.0.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.3.3

 

The Development Requires

ini files

29/11 2016

v2.0-beta.1

2.0.0.0-beta1 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.3.3

 

The Development Requires

ini files

15/06 2016

v1.7.1

1.7.1.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.3.3

 

The Development Requires

ini files

01/06 2015

v1.7.0

1.7.0.0 http://jelix.org

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

  Sources   Download

LGPL-2.1

The Requires

  • php >=5.3.3

 

The Development Requires

ini files