SPHPlayground API
SPHPlayground
sphplayground sphplayground

The Strings class

Strings is a utility class for string manipulation. It contains static methods for multibyte string manipulation and comparison.

Synopsis
final class Strings
public const TYPE_ALPHA
public const TYPE_ALPHANUM
public const TYPE_BINARY
An octal number is a number that consists of the digits 0 to 7. The number must either have at least one leading zero, or it must be prefixed with 0o
public const TYPE_OCTAL
public const TYPE_HEX
public const TYPE_BLANK
public const TYPE_NUM
public const CASE_UPPER
public const CASE_LOWER
public const CASE_TITLE
Performs a regular expression match
public static match(string $string, string $pattern):bool
Replaces a regular expression with multibyte support
public static regexReplace(string $string, string $pattern, string $replacement, ?string $option = null, ?string $encoding = null):string
public static substringReplace(string $string, string $replace, int $offset, int $length, ?string $encoding = null):string
Returns a reversed string
public static reverse(string $string, ?string $encoding = null):string
Returns a string with whitespace removed from the start and end of the string
public static trim(string $string, ?string $charMask = null, ?string $encoding = null):string
Returns a string with whitespace removed from the start of the string
public static trimLeft(string $string, ?string $charMask = null, ?string $encoding = null):string
Returns a string with whitespace removed from the end of the string
public static trimRight(string $string, ?string $charMask = null, ?string $encoding = null):string
Trims the string and replaces consecutive whitespace characters with a single space
public static collapseWhitespace(string $string):string
Checks whether the haystack string contains all needles
public static containsAll(string $haystack, array $needles):bool
Checks whether the string contains any of the needles
public static containsAny(string $haystack, array $needles):bool
Returns the character at $index, with indexes starting at 0
public static charAt(string $string, int $index, ?string $encoding = null):string
Returns an array consisting of the characters in the string.
public static toArray(string $string, ?string $encoding = null):array
Checks if the string is JSON
public static typeIs(string $string, string|int $type):bool