PHP code example of yosymfony / toml
1. Go to this page and download the library: Download yosymfony/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/ */
yosymfony / toml example snippets
use Yosymfony\Toml\Toml;
$array = Toml::Parse('key = [1,2,3]');
print_r($array);
$array = Toml::ParseFile('example.toml');
print_r($array);
$object = Toml::Parse('key = [1,2,3]', true);
use Yosymfony\Toml\TomlBuilder;
$tb = new TomlBuilder();
$result = $tb->addComment('Toml file')
->addTable('data.string')
->addValue('name', "Toml", 'This is your name')
->addValue('newline', "This string has a \n new line character.")
->addValue('winPath', "C:\\Users\\nodejs\\templates")
->addValue('literal', '@<\i\c*\s*>') // literals starts with '@'.
->addValue('unicode', 'unicode character: ' . json_decode('"\u03B4"'))
->addTable('data.bool')
->addValue('t', true)
->addValue('f', false)
->addTable('data.integer')
->addValue('positive', 25, 'Comment inline.')
->addValue('negative', -25)
->addTable('data.float')
->addValue('positive', 25.25)
->addValue('negative', -25.25)
->addTable('data.datetime')
->addValue('datetime', new \Datetime())
->addComment('Related to arrays')
->addTable('data.array')
->addValue('simple', array(1,2,3))
->addValue('multiple', array(
array(1,2),
array('abc', 'def'),
array(1.1, 1.2),
array(true, false),
array( new \Datetime()) ))
->addComment('Array of tables')
->addArrayOfTable('fruit') // Row
->addValue('name', 'apple')
->addArrayOfTable('fruit.variety')
->addValue('name', 'red delicious')
->addArrayOfTable('fruit.variety')
->addValue('name', 'granny smith')
->addArrayOfTable('fruit') // Row
->addValue('name', 'banana')
->addArrayOfTable('fruit.variety')
->addValue('name', 'plantain')
->getTomlString(); // Generate the TOML string