1. Go to this page and download the library: Download spomky-labs/cbor-php 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/ */
use CBOR\ByteStringObject; // Byte String
use CBOR\IndefiniteLengthByteStringObject; // Indefinite Length Byte String
// Create a Byte String with value "Hello"
$object = ByteStringObject::create('Hello');
// Create an Indefinite Length Byte String with value "Hello" ("He" + "" + "ll" + "o")
$object = IndefiniteLengthByteStringObject::create()
->append('He')
->append('')
->append('ll')
->append('o')
;
use CBOR\TextStringObject; // Text String
use CBOR\IndefiniteLengthTextStringObject; // Indefinite Length Text String
// Create a Text String with value "(。◕‿◕。)⚡"
$object = TextStringObject::create('(。◕‿◕。)⚡');
// Create an Indefinite Length Text String with value "(。◕‿◕。)⚡" ("(。◕" + "" + "‿◕" + "。)⚡")
$object = IndefiniteLengthTextStringObject::create()
->append('(。◕')
->append('')
->append('‿◕')
->append('。)⚡')
;
use CBOR\ListObject; // List
use CBOR\IndefiniteLengthListObject; // Infinite List
use CBOR\TextStringObject;
use CBOR\UnsignedIntegerObject;
// Create a List with a single item
$object = ListObject::create()
->add(TextStringObject::create('(。◕‿◕。)⚡'))
;
// Create an Infinite List with several items
$object = IndefiniteLengthListObject::create()
->add(TextStringObject::create('(。◕‿◕。)⚡'))
->add(UnsignedIntegerObject::create(25))
;
use CBOR\MapObject; // Map
use CBOR\IndefiniteLengthMapObject; // Infinite Map
use CBOR\ByteStringObject;
use CBOR\TextStringObject;
use CBOR\UnsignedIntegerObject;
use CBOR\NegativeIntegerObject;
// Create a Map with a single item
$object = MapObject::create()
->add(UnsignedIntegerObject::create(25), TextStringObject::create('(。◕‿◕。)⚡'))
;
// Create an Infinite Map with several items
$object = IndefiniteLengthMapObject::create()
->append(ByteStringObject::create('A'), NegativeIntegerObject::create(-652))
->append(UnsignedIntegerObject::create(25), TextStringObject::create('(。◕‿◕。)⚡'))
;
use CBOR\Tag\TimestampTag;
use CBOR\UnsignedIntegerObject;
// Create an unsigned object that represents the current timestamp
$object = UnsignedIntegerObject::create(time()); // e.g. 1525873787
//We tag the object with the Timestamp Tag
$taggedObject = TimestampTag::create($object); // Returns a \DateTimeImmutable object with timestamp at 1525873787
use CBOR\OtherObject\FalseObject;
use CBOR\OtherObject\NullObject;
use CBOR\OtherObject\UndefinedObject;
$object = FalseObject::create();
$object = NullObject::create();
$object = UndefinedObject::create();
use CBOR\MapObject;
use CBOR\OtherObject\UndefinedObject;
use CBOR\TextStringObject;
use CBOR\ListObject;
use CBOR\NegativeIntegerObject;
use CBOR\UnsignedIntegerObject;
use CBOR\OtherObject\TrueObject;
use CBOR\OtherObject\FalseObject;
use CBOR\OtherObject\NullObject;
use CBOR\Tag\DecimalFractionTag;
use CBOR\Tag\TimestampTag;
$object = MapObject::create()
->add(
TextStringObject::create('(。◕‿◕。)⚡'),
ListObject::create([
TrueObject::create(),
FalseObject::create(),
UndefinedObject::create(),
DecimalFractionTag::createFromExponentAndMantissa(
NegativeIntegerObject::create(-2),
UnsignedIntegerObject::create(1234)
),
])
)
->add(
UnsignedIntegerObject::create(2000),
NullObject::create()
)
->add(
TextStringObject::create('date'),
TimestampTag::create(UnsignedIntegerObject::create(1577836800))
)
;
use CBOR\StringStream;
// CBOR object (in hex for the example)
$data = hex2bin('fb3fd5555555555555');
// String Stream
$stream = StringStream::create($data);
// Load the data
$object = $decoder->decode($stream); // Return a CBOR\OtherObject\DoublePrecisionFloatObject class with normalized value ~0.3333 (1/3)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.