PHP code example of kunststube / rison

1. Go to this page and download the library: Download kunststube/rison 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/ */

    

kunststube / rison example snippets




$data = array('foo', 'bar' => array('baz'));

// encoding
$rison = Kunststube\Rison\rison_encode($data);
var_dump($rison);

// decoding
$data = Kunststube\Rison\rison_decode($rison);
var_dump($data);



use Kunststube\Rison;

$data = array('foo', 'bar' => array('baz'));

// encoding
try {
    $encoder = new Rison\RisonEncoder($data);
    $rison   = $encoder->encode();
    var_dump($rison);
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
}

// decoding
try {
    $decoder = new Rison\RisonDecoder($rison);
    $data    = $decoder->decode();
    var_dump($data);
} catch (Rison\RisonParseErrorException $e) {
    echo $e->getMessage(), ' in string: ', $e->getRison();
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
}