donatj/php-ini-builder

PHP `parse_ini_string` Compatible INI Builder

v0.2.0 2021-09-01 04:52 UTC

README

Latest Stable Version License Build Status Scrutinizer Code Quality

Create PHP parse_ini_string / parse_ini_file compatible INI strings from associative arrays.

Requirements

  • php: >=7.1
  • ext-ctype: *

Installing

Install the latest version with:

composer require 'donatj/php-ini-builder'

Example

Here is a simple example script:

<?php

require __DIR__ . '/../vendor/autoload.php';

$data = [
	'Title'   => [
		'str' => 'awesome',
		'int' => 7,
		'flt' => 10.2,
	],
	'Title 2' => [
		'bool' => true,
		'arr'  => [
			'a', 'b', 'c', 6 => 'd', 'e', 'key' => 'f',
		],
	],
];

$builder = new \donatj\Ini\Builder;

echo $builder->generate($data);

Which outputs:

[Title]
str = 'awesome'
int = 7
flt = 10.2

[Title 2]
bool = true
arr[] = 'a'
arr[] = 'b'
arr[] = 'c'
arr[6] = 'd'
arr[] = 'e'
arr[key] = 'f'

Documentation

See: DOCS.md