Index Documentation

WString
in package

FinalYes

Provides various helper methods for multibyte strings.

Table of Contents

Constants

TRIM_CHARS  = "\x00\t\n\v\f\r …  ᠎           ​‌‍

  ⁠ "
Default characters for ::trim, ::trimStart and ::trimEnd.

Methods

countUnique()  : int
Counts unique characters in a string.
endsWith()  : bool
Checks if a multibyte string ends with a given substring.
nullOrWhitespace()  : bool
Check if a multibyte string is null or whitespace.
reverse()  : string
Reverses a multibyte string.
startsWith()  : bool
Checks if a multibyte string starts with a given substring.
trim()  : string
Strip whitespace (or other characters) from the start and end of a multibyte string.
trimEnd()  : string
Strip whitespace (or other characters) from the end of a multibyte string.
trimStart()  : string
Strip whitespace (or other characters) from the start of a multibyte string.

Constants

TRIM_CHARS

Default characters for ::trim, ::trimStart and ::trimEnd.

public string TRIM_CHARS = "\x00\t\n\v\f\r …  ᠎           ​‌‍

  ⁠ "

Methods

countUnique()

Counts unique characters in a string.

public static countUnique(Stringable|string $string[, string|null $encoding = null ]) : int
Parameters
$string : Stringable|string

String to count unique characters of.

$encoding : string|null = null

String character encoding. null for mb_internal_encoding value.

Return values
int

Unique character count.

endsWith()

Checks if a multibyte string ends with a given substring.

public static endsWith(Stringable|string $haystack, Stringable|string $needle[, string|null $encoding = null ]) : bool
Parameters
$haystack : Stringable|string

String to search in.

$needle : Stringable|string

Sustring to search for in the haystack.

$encoding : string|null = null

String character encoding. null for mb_internal_encoding value.

Return values
bool

true if haystack ends with needle, false otherwise.

nullOrWhitespace()

Check if a multibyte string is null or whitespace.

public static nullOrWhitespace(Stringable|string|null $string[, string|null $encoding = null ]) : bool
Parameters
$string : Stringable|string|null

String to check for whitespace.

$encoding : string|null = null

String character encoding. null for mb_internal_encoding value.

Return values
bool

true if the string is whitespace, false if not.

reverse()

Reverses a multibyte string.

public static reverse(Stringable|string $string[, string|null $encoding = null ]) : string
Parameters
$string : Stringable|string

String to reverse.

$encoding : string|null = null

String character encoding. null for mb_internal_encoding value.

Return values
string

Reversed string.

startsWith()

Checks if a multibyte string starts with a given substring.

public static startsWith(Stringable|string $haystack, Stringable|string $needle[, string|null $encoding = null ]) : bool
Parameters
$haystack : Stringable|string

String to search in.

$needle : Stringable|string

Sustring to search for in the haystack.

$encoding : string|null = null

String character encoding. null for mb_internal_encoding value.

Return values
bool

true if haystack begins with needle, false otherwise.

trim()

Strip whitespace (or other characters) from the start and end of a multibyte string.

public static trim(Stringable|string $string[, string $chars = self::TRIM_CHARS ][, string|null $encoding = null ][, string|null $charsEncoding = null ]) : string
Parameters
$string : Stringable|string

Input string.

$chars : string = self::TRIM_CHARS

Characters to strip. List all characters you want. .. operator from trim is not supported.

$encoding : string|null = null

String character encoding. null for mb_internal_encoding value.

$charsEncoding : string|null = null
Return values
string

Trimmed string.

trimEnd()

Strip whitespace (or other characters) from the end of a multibyte string.

public static trimEnd(Stringable|string $string[, string $chars = self::TRIM_CHARS ][, string|null $encoding = null ][, string|null $charsEncoding = null ]) : string
Parameters
$string : Stringable|string

Input string.

$chars : string = self::TRIM_CHARS

Characters to strip. List all characters you want. .. operator from rtrim is not supported.

$encoding : string|null = null

String character encoding. null for mb_internal_encoding value.

$charsEncoding : string|null = null
Return values
string

Trimmed string.

trimStart()

Strip whitespace (or other characters) from the start of a multibyte string.

public static trimStart(Stringable|string $string[, string $chars = self::TRIM_CHARS ][, string|null $encoding = null ][, string|null $charsEncoding = null ]) : string
Parameters
$string : Stringable|string

Input string.

$chars : string = self::TRIM_CHARS

Characters to strip. List all characters you want. .. operator from ltrim is not supported.

$encoding : string|null = null

String character encoding. null for mb_internal_encoding value.

$charsEncoding : string|null = null
Return values
string

Trimmed string.


        
On this page

Search results