Skip to content

dahlia/bencodex-php

Repository files navigation

Bencodex reader/writer for PHP

Packagist Version MIT License GitHub Actions Status

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) }

Requirements

PHP Version Requirement

  • PHP 5.4 or later
  • iconv extension (--with-iconv)

Type correspondences

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

Usage

The above APIs are merely façade, and optional parameters are omitted. See the complete API docs as well.

Footnotes

  1. One-way types only available for encoding. 2

  2. One-way types only available for decoding. 2 3

  3. Determined by array_is_list() function.