Bencodex

Bencodex

Namespaces

Codec
Readers
Writers

Table of Contents

encode()  : string
Encodes the given value into Bencodex data.
decode()  : mixed
Decodes the given Bencodex data into a PHP value.

Functions

encode()

Encodes the given value into Bencodex data.

encode(mixed $value[, string|null $textEncoding = 'utf-8' ][, string|null $keyEncoding = 'utf-8' ][, bool $byteOrderMark = false ]) : string

This is a facade of Encoder class.

Parameters
$value : mixed

The value to be encoded in Bencodex.

$textEncoding : string|null = 'utf-8'

Determines what text encoding the PHP strings you want to encode are in. If the PHP strings are binary data and not Unicode text, then this should be set to null. UTF-8 by default.

$keyEncoding : string|null = 'utf-8'

Determines what text encoding the string keys of the PHP arrays you want to encode are in. If the PHP string keys are binary keys and not Unicode keys, they should be set to null. UTF-8 by default.

$byteOrderMark : bool = false

Whether to respect BOMs (byte order marks). If turned on, strings without BOMs are considered as binary and BOMs are stripped after encoding. If turned off (default), there's no special treatment for BOM.

Tags
throws
TextEncodingError

Thrown when the given text encoding is invalid or unsupported by iconv.

Return values
string

The encoded Bencodex data.

decode()

Decodes the given Bencodex data into a PHP value.

decode(string $bencodex[, string $textEncoding = 'utf-8' ][, bool $byteOrderMark = false ]) : mixed

This is a facade of Decoder class.

Parameters
$bencodex : string

The Bencodex data to decode.

$textEncoding : string = 'utf-8'

Determines what text encoding Bencodex text values are decoded to PHP strings in.

$byteOrderMark : bool = false

Whether to prepend BOMs (byte order marks). If turned on, Bencodex text values are decoded to PHP strings with BOMs whether the original text has BOM or not. If turned off (default), BOM is added to the decoded PHP string if and only if the original Bencodex text has BOM.

Return values
mixed

A decoded value.

Search results