fandogh/php-ubjson

Maintainers

Details

github.com/pi0/php-ubjson

Source

Fund package maintenance!
pi0

v0.2.2 2016-07-30 18:22 UTC

This package is not auto-updated.

Last update: 2024-05-25 17:12:07 UTC


README

Packagist Packagist

A library to read and write to the Universal Binary JSON (Draft 9) format using PHP

Install using composer

Using command line:

composer require fandogh/php-ubjson

Or add this to your composer.json file:

"require": {
  ...
  "fandogh/php-ubjson": "^0.2.2",
  ...
}

Usage

PLEASE NOTE THAT ENCODED RESULT IS A BINARY STRING and some charachters are non printable!!

// Don't forget to require autoload.php with correct path
require './vendor/autoload.php';

// Test data
$payload = ['hello'=>123];

// Encode using UBJSON
$encoded = \UBJSON::encode($payload);

# Incorrect! 
echo($encoded); // {SU�helloU{}

# Correct!
echo(bin2hex($encoded)); // "7b53550568656c6c6f557b7d"

// Test decoding
$decoded = \UBJSON::decode($encoded);

var_dump($decoded); // array(1) { ["hello"]=> int(123) }

Licence

This code is distributed under BSD license.