PHP code example of hypnotox / toml

1. Go to this page and download the library: Download hypnotox/toml library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hypnotox / toml example snippets


use HypnoTox\Toml\TomlFactory;

$factory = new TomlFactory();
$toml = $factory->fromString('
[server]
host = "localhost"
port = 8080
enabled = true
');

$toml->get('server.host');    // "localhost"
$toml->get('server.port');    // 8080
$toml->get('server.enabled'); // true
$toml->toArray();             // ['server' => ['host' => 'localhost', 'port' => 8080, 'enabled' => true]]

use HypnoTox\Toml\Toml;

$toml = Toml::fromArray([
    'title' => 'My App',
    'database' => [
        'host' => '127.0.0.1',
        'port' => 5432,
        'enabled' => true,
    ],
]);

echo $toml->toString();
// title = "My App"
//
// [database]
// host = "127.0.0.1"
// port = 5432
// enabled = true

// Immutable set (returns a new instance)
$updated = $toml->set('server.host', '0.0.0.0');

// Get as PHP array
$array = $toml->toArray();

// Encode back to TOML string
$string = $toml->toString();