Documentation

IniExport helper

Table of Contents 

Presentation

Helper used to export data in INI format.

Usage

The static generate() method takes an associative array as a parameter and converts it to an INI stream.

use \Temma\Utils\IniExport as TµIniExport;

$data = [
    'key1' => 'value1',
    'key2' => 'value2',
];
$ini = TµIniExport::generate($data);
/*
key1="value1"
key2="value2"
*/

$data = [
    'key1' => [
        'value1.1',
        'value1.2',
        'value1.3',
    ],
    'key2' => 'value2',
];
$ini = TµIniExport::generate($data);
/*
key1[]="value1.1"
key1[]="value1.2"
key1[]="value1.3"
key2="value2"
*/

If the second parameter is set to true, the INI export will use sections.

use \Temma\Utils\IniExport as TµIniExport;

$data = [
    'user1' => [
        'name' => 'Alice',
        'age'  => 28,
    ],
    'user2' => [
        'name' => 'Bob',
        'age'  => 54,
        'site' => [
            'bob.com',
            'bob.net',
        ],
    ],
    'user3' => [
        'name'  => 'Camille',
        'age'   => 37,
        'phone' => [
            'home' => '111222333',
            'work' => '444555666',
        ],
    ],
];
$ini = \Temma\Utils\IniExport::generate($data, true);
/*
[user1]
name="Alice"
age=28
[user2]
name="Bob"
age=54
site[]="bob.com"
site[]="bob.net"
[user3]
name="Camille"
age=37
phone[home]="111222333"
phone[work]="444555666"
*/
Previous: HTMLCleaner helper
Next: Json helper

Table of Contents