UTCode for PHP
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src/UTCode
.gitignore
README.md
composer.json

README.md

UTCode for PHP

Install via Composer

$ mkdir project_name
$ cd project_name
$ composer require jotjunior/php-utcode:dev-master

Examples

Encoding an Array

$array = [
    'id'        => 1,
    'firstName' => 'John',
    'lastName'  => 'doe',
    'ratio'     => 3.8,
    'category'  => [
        'id'   => 1234,
        'name' => 'Test User'
    ]
];
$code = new Encode($array);
echo $code, PHP_EOL;

Result: ut:d:k2:idi:1ek9:firstNameu8:Sm9obg==k8:lastNameu4:RG9lk5:ratiof:3.800000zk8:categoryd:k2:idi:1234ek4:nameu12:VGVzdCBVc2Vyee

Encoding a PHP Object

$object = new \stdClass();
$object->id = 1;
$object->firstName = 'John';
$object->lastName = 'Doe';
$object->ratio = 3.8;
$object->category = new \stdClass();
$object->category->id = 1334;
$object->category->name = 'Test User';
$code = new Encode($object);
echo $code, PHP_EOL;

Result: ut:d:k2:idi:1ek9:firstNameu8:Sm9obg==k8:lastNameu4:RG9lk5:ratiof:3.800000zk8:categoryd:k2:idi:1234ek4:nameu12:VGVzdCBVc2Vyee

Encoding a JSON string

$json
    = '{
   "id": 1,
   "firstName": "John",
   "lastName": "Doe",
   "ratio": 3.8,
   "category": {
       "id": 1234,
       "name": "Test User"
   }
}';
$code = new Encode($json);
echo $code, PHP_EOL;

Result: ut:d:k2:idi:1ek9:firstNameu8:Sm9obg==k8:lastNameu4:RG9lk5:ratiof:3.800000zk8:categoryd:k2:idi:1234ek4:nameu12:VGVzdCBVc2Vyee