Strings

Common String Functions

author

Jim Wigginton terrafrost@php.net

package

Default

Methods

Constant Time Base64-decoding

base64_decode(string $data): string
static

ParagoneIE\ConstantTime doesn't use libsodium if it's available so we'll do so ourselves. see https://github.com/paragonie/constant_time_encoding/issues/39

Arguments

$data

string

Response

string

Constant Time Base64-encoding

base64_encode(string $data): string
static

Arguments

$data

string

Response

string

Constant Time Base64-decoding (URL safe)

base64url_decode(string $data): string
static

Arguments

$data

string

Response

string

Constant Time Base64-encoding (URL safe)

base64url_encode(string $data): string
static

Arguments

$data

string

Response

string

Convert bits to binary data

bin2bits(string $x, $trim = true): string
static

Arguments

$x

string

$trim

Response

string

Constant Time Hex Encoder

bin2hex(string $data): string
static

Arguments

$data

string

Response

string

Convert binary data into bits

bits2bin(string $x): string
static

bin2hex / hex2bin refer to base-256 encoded data as binary, whilst decbin / bindec refer to base-2 encoded data as binary. For the purposes of this function, bin refers to base-256 encoded data whilst bits refers to base-2 encoded data

Arguments

$x

string

Response

string

Expand a pack string

formatPack(string $format): string
static

Converts C5 to CCCCC, for example.

Arguments

$format

string

Response

string

Constant Time Hex Decoder

hex2bin(string $data): string
static

Arguments

$data

string

Response

string

Increment the current string

increment_str(string &$var): string
static

Arguments

$var

string

Response

string

Find whether the type of a variable is string (or could be converted to one)

is_stringable(mixed $var): boolean
static
psalm-assert-if-true

string|\Stringable $var

Arguments

$var

mixed

Response

boolean

Create SSH2-style string

packSSH2(string $format,string|integer|float|array|boolean $elements): string
static

Arguments

$format

string

$elements

string|integer|float|array|boolean

Response

string

String Pop

pop(string &$string,integer $index = 1): string
static

Inspired by array_pop

Arguments

$string

string

$index

integer

Response

string

String Shift

shift(string &$string,integer $index = 1): string
static

Inspired by array_shift

Arguments

$string

string

$index

integer

Response

string

Switch Endianness Bit Order

switchEndianness(string $x): string
static

Arguments

$x

string

Response

string

Parse SSH2-style string

unpackSSH2(string $format,string &$data): mixed
static

Returns either an array or a boolean if $data is malformed.

Valid characters for $format are as follows:

C = byte b = boolean (true/false) N = uint32 Q = uint64 s = string i = mpint L = name-list

uint64 is not supported.

Arguments

$format

string

$data

string

Response

mixed