bhutanio / bencode
Bencode 序列化器,用于 Laravel
2.0.2
2020-09-14 18:50 UTC
Requires
- php: >=7.1
- illuminate/support: >=5.0
Requires (Dev)
- phpunit/phpunit: >=7.0
README
此库允许开发者在 Laravel 中对 bencoded 数据字符串进行编码和解码。有关 bencode 的更多信息,请参阅 维基百科。该格式主要用于 .torrent 文件规范。
安装
通过 Composer
$ composer require bhutanio/bencode
使用方法
编码数组
<?php use Bhutanio\Bencode\Bencode; $data = array( "string" => "bar", "integer" => 42, "array" => array( "one", "two", "three", ), ); echo Bencode::encode($data);
以上代码生成以下字符串:d5:arrayl3:one3:two5:threee7:integeri42e6:string3:bare
。
解码字符串
<?php use Bhutanio\Bencode\Bencode; $string = "d5:arrayl3:one3:two5:threee7:integeri42e6:string3:bare"; print_r(Bencode::decode($string));
以上代码生成以下输出
Array
(
[array] => Array
(
[0] => one
[1] => two
[2] => three
)
[integer] => 42
[string] => bar
)
测试
$ cp phpunit.xml.dst phpunit.xml $ vendor/bin/phpunit -c phpunit.xml
许可协议
MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件。