PHP code example of mfonte / fast-toon
1. Go to this page and download the library: Download mfonte/fast-toon 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/ */
mfonte / fast-toon example snippets
use Mfonte\FastToon\Toon;
$data = [
'users' => [
['id' => 1, 'name' => 'Alice', 'active' => true],
['id' => 2, 'name' => 'Bob', 'active' => false],
['id' => 3, 'name' => 'Charlie', 'active' => true],
]
];
$toon = toon_encode($data);
// Output:
// users[3]{id,name,active}:
// 1|Alice|T
// 2|Bob|F
// 3|Charlie|T
$decoded = toon_decode($toon);
use Mfonte\FastToon\Toon;
$toon = Toon::encode($data)
->withFlags(TOON_THROW_ON_ERROR | TOON_KEY_FOLDING)
->withDepth(100)
->toString();
$decoded = Toon::decode($toon)
->withOptions(['strict' => true])
->toArray();
// Combine flags with bitwise OR
$toon = toon_encode($data, TOON_THROW_ON_ERROR | TOON_KEY_FOLDING);
// Use tab delimiter for tabular output
$toon = toon_encode($data, TOON_TAB_DELIMITER);
$data = toon_decode($toon, TOON_STRICT | TOON_THROW_ON_ERROR);
$result = toon_encode($data);
if ($result === false) {
echo toon_last_error_msg();
}
try {
$toon = toon_encode($data, TOON_THROW_ON_ERROR);
} catch (\Mfonte\FastToon\Exceptions\EncodingException $e) {
// Handle exception
}
bash
# Check code style (PHP 7.4+, php-cs-fixer 3.x)
composer cs-check
# Fix code style (PHP 7.4+, php-cs-fixer 3.x)
composer cs-fix
# Check code style (PHP 7.0-7.3, php-cs-fixer 2.x)
composer cs-check:v2
# Fix code style (PHP 7.0-7.3, php-cs-fixer 2.x)
composer cs-fix:v2