This package implements Bencodex serialization format which extends Bencoding. Complianet with Bencodex 1.2.
php > echo Bencodex\encode(['foo' => 123, 'bar' => [true, false]]);
du3:barltfeu3:fooi123ee
php > var_dump(Bencodex\decode('du3:barltfeu3:fooi123ee'));
object(stdClass)#4 (2) {
["bar"]=>
array(2) {
[0]=>
bool(true)
[1]=>
bool(false)
}
["foo"]=>
int(123)
}- PHP 5.4 or later
- iconv extension (
--with-iconv)
| PHP | Bencodex |
|---|---|
| Null | Null |
| Boolean | Boolean |
| Integer | Integer |
| Double1 | Integer (truncated) |
| Numeric string2 | Integer ≥ PHP_INT_MAX |
| String which can be decoded as Unicode | Text2 |
| String otherwise | Binary2 |
| List-like array3 | List |
| Map-like array1 | Dictionary |
| Object | Dictionary |
\Bencodex\encode(mixed $value): string: Encodes a PHP$valueinto Bencodex data.\Bencodex\decode(string $bencodex): mixed: Decodes Bencodex data into a PHP value.
The above APIs are merely façade, and optional parameters are omitted. See the complete API docs as well.