Strings
class Strings
String tools library.
Constants
TRIM_CHARACTERS |
|
Methods
Checks if the string is valid for UTF-8 encoding.
Removes invalid code unit sequences from UTF-8 string.
Returns a specific character in UTF-8 from code point (0x0 to 0xD7FF or 0xE000 to 0x10FFFF).
Starts the $haystack string with the prefix $needle?
Ends the $haystack string with the suffix $needle?
Does $haystack contain $needle?
Returns a part of UTF-8 string.
Removes special controls characters and normalizes line endings, spaces and normal form to NFC in UTF-8 string.
Standardize line endings to unix-like.
Converts UTF-8 string to ASCII.
Converts UTF-8 string to web safe characters [a-z0-9-] text.
Truncates UTF-8 string to maximal length.
Indents UTF-8 string from the left.
Converts UTF-8 string to lower case.
Converts first character to lower case.
Converts UTF-8 string to upper case.
Converts first character to upper case.
Capitalizes UTF-8 string.
Case-insensitive compares UTF-8 strings.
Finds the length of common prefix of strings.
Returns number of characters (not bytes) in UTF-8 string.
Strips whitespace from UTF-8 string.
Pad a UTF-8 string to a certain length with another string.
Pad a UTF-8 string to a certain length with another string.
Reverse string.
Returns part of $haystack before $nth occurence of $needle (negative value means searching from the end).
Returns part of $haystack after $nth occurence of $needle (negative value means searching from the end).
Returns position of $nth occurence of $needle in $haystack (negative value means searching from the end).
Splits string by a regular expression.
Performs a regular expression match. Accepts flag PREG_OFFSET_CAPTURE (returned in bytes).
Performs a global regular expression match. Accepts flag PREG_OFFSET_CAPTURE (returned in bytes), PREG_SET_ORDER is default.
Perform a regular expression search and replace.
No description
Details
at line 29
static bool
checkEncoding(string $s)
Checks if the string is valid for UTF-8 encoding.
at line 38
static string
fixEncoding(string $s)
Removes invalid code unit sequences from UTF-8 string.
at line 49
static string
chr(int $code)
Returns a specific character in UTF-8 from code point (0x0 to 0xD7FF or 0xE000 to 0x10FFFF).
at line 61
static bool
startsWith(string $haystack, string $needle)
Starts the $haystack string with the prefix $needle?
at line 70
static bool
endsWith(string $haystack, string $needle)
Ends the $haystack string with the suffix $needle?
at line 79
static bool
contains(string $haystack, string $needle)
Does $haystack contain $needle?
at line 88
static string
substring(string $s, int $start, int $length = null)
Returns a part of UTF-8 string.
at line 104
static string
normalize(string $s)
Removes special controls characters and normalizes line endings, spaces and normal form to NFC in UTF-8 string.
at line 129
static string
normalizeNewLines(string $s)
Standardize line endings to unix-like.
at line 138
static string
toAscii(string $s)
Converts UTF-8 string to ASCII.
at line 178
static string
webalize(string $s, string $charlist = null, bool $lower = true)
Converts UTF-8 string to web safe characters [a-z0-9-] text.
at line 193
static string
truncate(string $s, int $maxLen, string $append = "…")
Truncates UTF-8 string to maximal length.
at line 214
static string
indent(string $s, int $level = 1, string $chars = "\t")
Indents UTF-8 string from the left.
at line 226
static string
lower(string $s)
Converts UTF-8 string to lower case.
at line 235
static string
firstLower(string $s)
Converts first character to lower case.
at line 244
static string
upper(string $s)
Converts UTF-8 string to upper case.
at line 253
static string
firstUpper(string $s)
Converts first character to upper case.
at line 262
static string
capitalize(string $s)
Capitalizes UTF-8 string.
at line 271
static bool
compare(string $left, string $right, int $len = null)
Case-insensitive compares UTF-8 strings.
at line 293
static string
findPrefix(array $strings)
Finds the length of common prefix of strings.
at line 314
static int
length(string $s)
Returns number of characters (not bytes) in UTF-8 string.
That is the number of Unicode code points which may differ from the number of graphemes.
at line 323
static string
trim(string $s, string $charlist = self::TRIM_CHARACTERS)
Strips whitespace from UTF-8 string.
at line 333
static string
padLeft(string $s, int $length, string $pad = ' ')
Pad a UTF-8 string to a certain length with another string.
at line 344
static string
padRight(string $s, int $length, string $pad = ' ')
Pad a UTF-8 string to a certain length with another string.
at line 355
static string
reverse(string $s)
Reverse string.
at line 365
static string|null
before(string $haystack, string $needle, int $nth = 1)
Returns part of $haystack before $nth occurence of $needle (negative value means searching from the end).
at line 378
static string|null
after(string $haystack, string $needle, int $nth = 1)
Returns part of $haystack after $nth occurence of $needle (negative value means searching from the end).
at line 391
static int|null
indexOf(string $haystack, string $needle, int $nth = 1)
Returns position of $nth occurence of $needle in $haystack (negative value means searching from the end).
at line 433
static array
split(string $subject, string $pattern, int $flags = 0)
Splits string by a regular expression.
at line 442
static array|null
match(string $subject, string $pattern, int $flags = 0, int $offset = 0)
Performs a regular expression match. Accepts flag PREG_OFFSET_CAPTURE (returned in bytes).
at line 456
static array
matchAll(string $subject, string $pattern, int $flags = 0, int $offset = 0)
Performs a global regular expression match. Accepts flag PREG_OFFSET_CAPTURE (returned in bytes), PREG_SET_ORDER is default.
at line 475
static string
replace(string $subject, string|array $pattern, string|callable $replacement = null, int $limit = -1)
Perform a regular expression search and replace.
at line 493
static
pcre(string $func, array $args)
internal |
No description
Traits
Static class.