PHP code example of mszewcz / php-json-utils

1. Go to this page and download the library: Download mszewcz/php-json-utils 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/ */

    

mszewcz / php-json-utils example snippets




use MS\Json\Utils\Utils;

$obj = new \stdClass();
$obj->flt = 5.5;
$obj->bool = true;

$data = ['int' => 8, 'str' => 'test/Ʃ', 'arr' => [$obj]];

$utils = new Utils();
try {
    $encoded = $utils->encode($data);
} catch (\Exception $e) {
    echo $e->getMessage();
}   

use MS\Json\Utils\Utils;

$json = '{"int":8,"str":"test/Ʃ","arr":[{"flt":5.5,"bool":true}]}';

$utils = new Utils();
try {
    $decoded = $utils->decode($json);
} catch (\Exception $e) {
    echo $e->getMessage();
}   
*/

use MS\Json\Utils\Utils;

$data = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eget purus ';
$data.= 'consectetur eros pellentesque ullamcorper. Sed justo tellus, porttitor non ';
$data.= 'porta ac, euismod eu mauris. Nam maximus pretium dapibus. Pellentesque in elit ';
$data.= 'placerat, sagittis justo id, elementum elit. Maecenas dignissim dui ac lectus ';
$data.= 'pretium condimentum. Morbi id ipsum in urna egestas varius in vitae quam. ';
$data.= 'Phasellus efficitur elementum sapien id dictum.';

$utils = new Utils();
$encoded = $utils->base64UrlEncode($data);

use MS\Json\Utils\Utils;

$data = 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4';
$data.= 'gTnVuYyBlZ2V0IHB1cnVzIGNvbnNlY3RldHVyIGVyb3MgcGVsbGVudGVzcXVlIHVsbGFtY29ycG';
$data.= 'VyLiBTZWQganVzdG8gdGVsbHVzLCBwb3J0dGl0b3Igbm9uIHBvcnRhIGFjLCBldWlzbW9kIGV1I';
$data.= 'G1hdXJpcy4gTmFtIG1heGltdXMgcHJldGl1bSBkYXBpYnVzLiBQZWxsZW50ZXNxdWUgaW4gZWxp';
$data.= 'dCBwbGFjZXJhdCwgc2FnaXR0aXMganVzdG8gaWQsIGVsZW1lbnR1bSBlbGl0LiBNYWVjZW5hcyB';
$data.= 'kaWduaXNzaW0gZHVpIGFjIGxlY3R1cyBwcmV0aXVtIGNvbmRpbWVudHVtLiBNb3JiaSBpZCBpcH';
$data.= 'N1bSBpbiB1cm5hIGVnZXN0YXMgdmFyaXVzIGluIHZpdGFlIHF1YW0uIFBoYXNlbGx1cyBlZmZpY';
$data.= '2l0dXIgZWxlbWVudHVtIHNhcGllbiBpZCBkaWN0dW0u';

$utils = new Utils();
$decoded = $utils->base64UrlDecode($data);
mszewcz/php-json-utils