PHP code example of corneltek / pjson

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

    

corneltek / pjson example snippets


use PJSON\PJSONEncoder;
use PJSON\DateTimeEncoder;
$encoder = new PJSONEncoder;
$encoder->setDateTimeEncoder(new DateTimeEncoder(DateTime::ATOM));
$encoder->setStringEncoder(function($value, $encoder) {
    return '"' . addcslashes($value) . '"';
});
$encoder->setClosureEncoder(function($closure, $encoder) {
    return $encoder->encode($closure(1,2,3));
});
$output = $encoder->encode([ ... PHP Array here ... ]);

$encoder = new PJSONEncoder;
$call = new JsFunctionCall('jQuery', ['#documentId']);
$encoder->encode($call); // outputs 'jQuery("#documentId")'
$encoder->encode(['a' => new JsSymbol('js_var')]); // outputs {"a": js_var}