Strings
class Strings
String tools library.
Constants
TRIM_CHARACTERS |
|
Methods
Checks if the string is valid in UTF-8 encoding.
Removes all invalid UTF-8 characters from a string.
Returns a specific character in UTF-8 from code point (number in range 0x0000..D7FF or 0xE000..10FFFF).
Returns a code point of specific character in UTF-8 (number in range 0x0000..D7FF or 0xE000..10FFFF).
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 specified by starting position and length. If start is negative, the returned string will start at the start'th character from the end of string.
Removes control characters, normalizes line breaks to \n
, removes leading and trailing blank lines,
trims end spaces on lines, normalizes UTF-8 to the normal form of NFC.
Standardize line endings to unix-like.
Converts UTF-8 string to ASCII, ie removes diacritics etc.
Modifies the UTF-8 string to the form used in the URL, ie removes diacritics and replaces all characters except letters of the English alphabet and numbers with a hyphens.
Truncates a UTF-8 string to given maximal length, while trying not to split whole words. Only if the string is truncated, an ellipsis (or something else set with third argument) is appended to the string.
Indents a multiline text from the left. Second argument sets how many indentation chars should be used, while the indent itself is the third argument (tab by default).
Converts all characters of UTF-8 string to lower case.
Converts the first character of a UTF-8 string to lower case and leaves the other characters unchanged.
Converts all characters of a UTF-8 string to upper case.
Converts the first character of a UTF-8 string to upper case and leaves the other characters unchanged.
Converts the first character of every word of a UTF-8 string to upper case and the others to lower case.
Compares two UTF-8 strings or their parts, without taking character case into account. If length is null, whole strings are compared, if it is negative, the corresponding number of characters from the end of the strings is compared, otherwise the appropriate number of characters from the beginning is compared.
Finds the common prefix of strings or returns empty string if the prefix was not found.
Returns number of characters (not bytes) in UTF-8 string.
Removes all left and right side spaces (or the characters passed as second argument) from a UTF-8 encoded string.
Pads a UTF-8 string to given length by prepending the $pad string to the beginning.
Pads UTF-8 string to given length by appending the $pad string to the end.
Reverses UTF-8 string.
Returns part of $haystack before $nth occurence of $needle or returns null if the needle was not found.
Returns part of $haystack after $nth occurence of $needle or returns null if the needle was not found.
Returns position in characters of $nth occurence of $needle in $haystack or null if the $needle was not found.
Splits a string into array by the regular expression. Parenthesized expression in the delimiter are captured.
Checks if given string matches a regular expression pattern and returns an array with first found match and each subpattern.
Finds all occurrences matching regular expression pattern and returns a two-dimensional array.
Replaces all occurrences matching regular expression $pattern which can be string or array in the form pattern => replacement
.
No description
Details
at line 29
static bool
checkEncoding(string $s)
Checks if the string is valid in UTF-8 encoding.
at line 38
static string
fixEncoding(string $s)
Removes all invalid UTF-8 characters from a string.
at line 49
static string
chr(int $code)
Returns a specific character in UTF-8 from code point (number in range 0x0000..D7FF or 0xE000..10FFFF).
at line 64
static int
ord(string $c)
Returns a code point of specific character in UTF-8 (number in range 0x0000..D7FF or 0xE000..10FFFF).
at line 82
static bool
startsWith(string $haystack, string $needle)
Starts the $haystack string with the prefix $needle?
at line 91
static bool
endsWith(string $haystack, string $needle)
Ends the $haystack string with the suffix $needle?
at line 100
static bool
contains(string $haystack, string $needle)
Does $haystack contain $needle?
at line 110
static string
substring(string $s, int $start, int|null $length = null)
Returns a part of UTF-8 string specified by starting position and length. If start is negative, the returned string will start at the start'th character from the end of string.
at line 130
static string
normalize(string $s)
Removes control characters, normalizes line breaks to \n
, removes leading and trailing blank lines,
trims end spaces on lines, normalizes UTF-8 to the normal form of NFC.
at line 155
static string
normalizeNewLines(string $s)
Standardize line endings to unix-like.
at line 164
static string
toAscii(string $s)
Converts UTF-8 string to ASCII, ie removes diacritics etc.
at line 230
static string
webalize(string $s, string|null $charlist = null, bool $lower = true)
Modifies the UTF-8 string to the form used in the URL, ie removes diacritics and replaces all characters except letters of the English alphabet and numbers with a hyphens.
at line 247
static string
truncate(string $s, int $maxLen, string $append = "…")
Truncates a UTF-8 string to given maximal length, while trying not to split whole words. Only if the string is truncated, an ellipsis (or something else set with third argument) is appended to the string.
at line 270
static string
indent(string $s, int $level = 1, string $chars = "\t")
Indents a multiline text from the left. Second argument sets how many indentation chars should be used, while the indent itself is the third argument (tab by default).
at line 283
static string
lower(string $s)
Converts all characters of UTF-8 string to lower case.
at line 292
static string
firstLower(string $s)
Converts the first character of a UTF-8 string to lower case and leaves the other characters unchanged.
at line 301
static string
upper(string $s)
Converts all characters of a UTF-8 string to upper case.
at line 310
static string
firstUpper(string $s)
Converts the first character of a UTF-8 string to upper case and leaves the other characters unchanged.
at line 319
static string
capitalize(string $s)
Converts the first character of every word of a UTF-8 string to upper case and the others to lower case.
at line 330
static bool
compare(string $left, string $right, int|null $length = null)
Compares two UTF-8 strings or their parts, without taking character case into account. If length is null, whole strings are compared, if it is negative, the corresponding number of characters from the end of the strings is compared, otherwise the appropriate number of characters from the beginning is compared.
at line 353
static string
findPrefix(array $strings)
Finds the common prefix of strings or returns empty string if the prefix was not found.
at line 376
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 387
static string
trim(string $s, string $charlist = self::TRIM_CHARACTERS)
Removes all left and right side spaces (or the characters passed as second argument) from a UTF-8 encoded string.
at line 397
static string
padLeft(string $s, int $length, string $pad = ' ')
Pads a UTF-8 string to given length by prepending the $pad string to the beginning.
at line 408
static string
padRight(string $s, int $length, string $pad = ' ')
Pads UTF-8 string to given length by appending the $pad string to the end.
at line 419
static string
reverse(string $s)
Reverses UTF-8 string.
at line 433
static string|null
before(string $haystack, string $needle, int $nth = 1)
Returns part of $haystack before $nth occurence of $needle or returns null if the needle was not found.
Negative value means searching from the end.
at line 446
static string|null
after(string $haystack, string $needle, int $nth = 1)
Returns part of $haystack after $nth occurence of $needle or returns null if the needle was not found.
Negative value means searching from the end.
at line 459
static int|null
indexOf(string $haystack, string $needle, int $nth = 1)
Returns position in characters of $nth occurence of $needle in $haystack or null if the $needle was not found.
Negative value of $nth
means searching from the end.
at line 505
static array
split(string $subject, string $pattern, bool|int $captureOffset = false, bool $skipEmpty = false, int $limit = -1, bool $utf8 = false)
Splits a string into array by the regular expression. Parenthesized expression in the delimiter are captured.
at line 529
static array|null
match(string $subject, string $pattern, bool|int $captureOffset = false, int $offset = 0, bool $unmatchedAsNull = false, bool $utf8 = false)
Checks if given string matches a regular expression pattern and returns an array with first found match and each subpattern.
at line 565
static array
matchAll(string $subject, string $pattern, bool|int $captureOffset = false, int $offset = 0, bool $unmatchedAsNull = false, bool $patternOrder = false, bool $utf8 = false)
Finds all occurrences matching regular expression pattern and returns a two-dimensional array.
Result is array of matches (ie uses by default PREG_SET_ORDER).
at line 602
static string
replace(string $subject, string|array $pattern, string|callable $replacement = '', int $limit = -1, bool $captureOffset = false, bool $unmatchedAsNull = false, bool $utf8 = false)
Replaces all occurrences matching regular expression $pattern which can be string or array in the form pattern => replacement
.
at line 660
static
pcre(string $func, array $args)
internal |
No description
Traits
Static class.