SPHPlayground API
SPHPlayground
sphplayground sphplayground

The MbString class

The MbString class is a wrapper for scalar string. It supports any common character encodings and thus it can deal with the issues concerning multibyte encodings in PHP.

Synopsis
$str is cast to a string prior to assignment, and if $encoding is not specified, it defaults to mb_internal_encoding().
final public __construct(string $str = '', ?string $encoding = null)
Returns the string value of the object
public __toString():string
Performs a regular expression match
public match(string $pattern):bool
Returns a string with whitespace removed from the start and end of the string
public trim(?string $charMask = null):MbString
Returns a string with whitespace removed from the start of the string
public trimLeft(?string $charMask = null):MbString
Returns a string with whitespace removed from the end of the string
public trimRight(?string $charMask = null):MbString
Trims the string and replaces consecutive whitespace characters with a single space
public collapseWhitespace():MbString
public contains(string $needle):bool
Checks whether the haystack string contains all $needles
public containsAll(string ... $needles):bool
Checks whether the string contains any of the needles
public containsAny(string ... $needles):bool
Checks whether the string starts with the given needles
public startsWith(string $needle):bool
Checks whether the string ends with the given needles
public endsWith(string $needle):bool
Returns the number of occurrences of $substring in the string
public countSubstr(string $substring, bool $caseSensitive = true):int
Perform a case folding
public convertCase(int $mode):MbString
public is(string|int $type):bool
Checks whether the string is empty
public isEmpty():bool
Returns the length of the string
public count():int
Perform a regular expression search and replace
public pregReplace(string $pattern, string $replacement, int $limit = -1, ?int $count = null):MbString
Replaces a regular expression with multibyte support
public eregReplace(string $pattern, string $replacement, ?string $option = null):MbString
Replaces all occurrences of $search in $str by $replacement
public replace(array|string $search, array|string $replacement):MbString
Returns a new instance with reversed string
public reverse():MbString
Returns the index of the first occurrence of $needle in the string
public strpos(string $needle, int $offset = 0):?int
Returns the character at $index, with indexes starting at 0
public charAt(int $index):?string
Returns an array consisting of the characters in the string
public toArray():array
Returns the encoding used
public getEncoding():string
Rewinds the Iterator to the first element
public rewind():void
Returns the current character
public current():?string
Return the key of the current character
public key():int
public next():void
Checks if current iterator position is valid
public valid():bool
Creates a string object from given str and encoding properties
public static create(Stringable|string|int|float|null $str = null, ?string $encoding = null):MbString