Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A bencode serializer for PHP 5.3+
PHP
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
nbproject
src
tests
.gitattributes
.gitignore
.travis.yml
LICENSE.md
README.md
composer.json
phpunit.xml.dist

README.md

Bencode serialization for PHP

Latest Version on Packagist Software License Build Status Quality Score Total Downloads

This library allows developers to encode or decode bencoded data strings in PHP 5.3+. More information about bencode can be found at Wikipedia. The format is primarily used in the .torrent file specification.

Install

Via Composer

$ composer require rych/bencode

Usage

Encoding an array

<?php

use Rych\Bencode\Bencode;

$data = array(
    "string" => "bar",
    "integer" => 42,
    "array" => array(
        "one",
        "two",
        "three",
    ),
);

echo Bencode::encode($data);

The above produces the string d5:arrayl3:one3:two5:threee7:integeri42e6:string3:bare.

Decoding a string

<?php

use Rych\Bencode\Bencode;

$string = "d5:arrayl3:one3:two5:threee7:integeri42e6:string3:bare";

print_r(Bencode::decode($string));

The above produces the the following output:

Array
(
    [array] => Array
        (
            [0] => one
            [1] => two
            [2] => three
        )

    [integer] => 42
    [string] => bar
)

Testing

$ vendor/bin/phpunit -c phpunit.dist.xml

License

The MIT License (MIT). Please see License File for more information.

Something went wrong with that request. Please try again.