A simple and complete bencode encoder/decoder
A simple, efficient and complete Bencode encoder/decoder for PHP.
Install the composer package.
use \PureBencode\Bencode; // encode $bencode = Bencode::encode($value); // decode $value = Bencode::decode($bencode);
Bencode::encode()accepts only PHP values which can be converted to their exact original by
Bencode::decode(). Those are
arrays whose contents are also valid.
arrays with keys of the form 0, 1, 2...n with be encoded as lists. All others will be encoded as dictionaries with their keys in sorted order.
- Any problems will result in a
\PureBencode\Exceptionwith an appropriate message.
That is all. Have fun