Craft 3 Class Reference

Class craft\helpers\StringHelper

Inheritance
craft\helpers\StringHelper » yii\helpers\StringHelper » yii\helpers\BaseStringHelper
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/helpers/StringHelper.php

This helper class provides various multi-byte aware string related manipulation and encoding methods.

Public Methods
Method Description Defined By
UUID() Generates a valid v4 UUID string. See [http://stackoverflow.com/a/2040279/684] craft\helpers\StringHelper
asciiCharMap() Returns ASCII character mappings, merging in any custom defined mappings from the 'customAsciiCharMappings' config setting. craft\helpers\StringHelper
base64UrlDecode() Decodes "Base 64 Encoding with URL and Filename Safe Alphabet" (RFC 4648). yii\helpers\BaseStringHelper
base64UrlEncode() Encodes string into "Base 64 Encoding with URL and Filename Safe Alphabet" (RFC 4648). yii\helpers\BaseStringHelper
basename() Returns the trailing name component of a path. yii\helpers\BaseStringHelper
byteLength() Returns the number of bytes in the given string. yii\helpers\BaseStringHelper
byteSubstr() Returns the portion of string specified by the start and length parameters. yii\helpers\BaseStringHelper
camelCase() Returns a camelCase version of the given string. Trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, as well as underscores. craft\helpers\StringHelper
charAt() Returns the character at a specific point in a potentially multibyte string. craft\helpers\StringHelper
charsAsArray() Returns an array consisting of the characters in the string. craft\helpers\StringHelper
collapseWhitespace() Trims the string and replaces consecutive whitespace characters with a single space. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space. craft\helpers\StringHelper
contains() Returns true if the string contains $needle, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false. craft\helpers\StringHelper
containsAll() Returns true if the string contains all $needles, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false. craft\helpers\StringHelper
containsAny() Returns true if the string contains any $needles, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false. craft\helpers\StringHelper
containsMb4() Detects whether the given string has any 4-byte UTF-8 characters. craft\helpers\StringHelper
convertToUtf8() Attempts to convert a string to UTF-8 and clean any non-valid UTF-8 characters. craft\helpers\StringHelper
countSubstrings() Returns the number of occurrences of $substring in the given string. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false. craft\helpers\StringHelper
countWords() Counts words in a string. yii\helpers\BaseStringHelper
decdec() Base64-decodes and decrypts a string generated by encenc(). craft\helpers\StringHelper
delimit() Returns a lowercase and trimmed string separated by the given delimiter. Delimiters are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces, dashes, and underscores. Alpha delimiters are not converted to lowercase. craft\helpers\StringHelper
dirname() Returns parent directory's path. yii\helpers\BaseStringHelper
encenc() Encrypts and base64-encodes a string. craft\helpers\StringHelper
encodeMb4() HTML-encodes any 4-byte UTF-8 characters. craft\helpers\StringHelper
encoding() Gets the current encoding of the given string. craft\helpers\StringHelper
endsWith() Returns true if the string ends with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false. craft\helpers\StringHelper
ensureLeft() Ensures that the string begins with $substring. If it doesn't, it's prepended. craft\helpers\StringHelper
ensureRight() Ensures that the string ends with $substring. If it doesn't, it's appended. craft\helpers\StringHelper
explode() Explodes string into array, optionally trims values and skips empty ones. yii\helpers\BaseStringHelper
first() Returns the first $n characters of the string. craft\helpers\StringHelper
floatToString() Safely casts a float to string independent of the current locale. yii\helpers\BaseStringHelper
hasLowerCase() Returns whether the given string has any lowercase characters in it. craft\helpers\StringHelper
hasUpperCase() Returns whether the given string has any uppercase characters in it. craft\helpers\StringHelper
indexOf() Returns the index of the first occurrence of $needle in the string, and false if not found. craft\helpers\StringHelper
indexOfLast() Returns the index of the last occurrence of $needle in the string,and false if not found. craft\helpers\StringHelper
insert() Inserts $substring into the string at the $index provided. craft\helpers\StringHelper
isAlpha() Returns true if the string contains only alphabetic chars, false otherwise. craft\helpers\StringHelper
isAlphanumeric() Returns true if the string contains only alphabetic and numeric chars, false otherwise. craft\helpers\StringHelper
isHexadecimal() Returns true if the string contains only hexadecimal chars, false otherwise. craft\helpers\StringHelper
isLowerCase() Returns true if the string contains only lowercase chars, false otherwise. craft\helpers\StringHelper
isUUID() Returns is the given string matches a v4 UUID pattern. craft\helpers\StringHelper
isUpperCase() Returns true if the string contains only uppercase chars, false otherwise. craft\helpers\StringHelper
isUtf8() Checks if the given string is UTF-8 encoded. craft\helpers\StringHelper
isWhitespace() Returns true if the string contains only whitespace chars, false otherwise. craft\helpers\StringHelper
last() Returns the last $number characters of the string. craft\helpers\StringHelper
length() Returns the length of the string. An alias for PHP's mb_strlen() function. craft\helpers\StringHelper
lines() Splits on newlines and carriage returns, returning an array of strings corresponding to the lines in the string. craft\helpers\StringHelper
lowercaseFirst() Converts the first character of the supplied string to lower case. craft\helpers\StringHelper
matchWildcard() Checks if the passed string would match the given shell wildcard pattern. yii\helpers\BaseStringHelper
normalizeNumber() Returns string representation of number value with replaced commas to dots, if decimal point of current locale is comma. yii\helpers\BaseStringHelper
padBoth() Returns a new string of a given length such that both sides of the string are padded. craft\helpers\StringHelper
padLeft() Returns a new string of a given length such that the beginning of the string is padded. craft\helpers\StringHelper
padRight() Returns a new string of a given length such that the end of the string is padded. craft\helpers\StringHelper
randomString() Generates a random string of latin alphanumeric characters that defaults to a $length of 36. If $extendedChars is set to true, additional symbols can be included in the string. Note that the generated string is not a cryptographically secure string. If you need a cryptographically secure string, use Craft::$app->security->generateRandomString(). craft\helpers\StringHelper
randomStringWithChars() Generates a random string of characters. Note that the generated string is not a cryptographically secure string. If you need a cryptographically secure string, use Craft::$app->security->generateRandomString(). craft\helpers\StringHelper
regexReplace() Replaces all occurrences of $pattern in $str by $replacement. An alias for mb_ereg_replace(). craft\helpers\StringHelper
removeLeft() Returns a new string with the prefix $substring removed, if present. craft\helpers\StringHelper
removeRight() Returns a new string with the suffix $substring removed, if present. craft\helpers\StringHelper
replace() Replaces all occurrences of $search in $str by $replacement. craft\helpers\StringHelper
reverse() Returns a reversed string. A multibyte version of strrev(). craft\helpers\StringHelper
safeTruncate() Truncates the string to a given length, while ensuring that it does not split words. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding t he desired length. craft\helpers\StringHelper
split() Splits a string into chunks on a given delimiter. craft\helpers\StringHelper
splitOnWords() Splits a string into an array of the words in the string. craft\helpers\StringHelper
startsWith() Returns true if the string begins with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false. craft\helpers\StringHelper
stripHtml() Strips HTML tags out of a given string. craft\helpers\StringHelper
substr() Returns the substring beginning at $start with the specified|null $length. It differs from the mb_substr() function in that providing a|null $length of null will return the rest of the string, rather than an empty string. craft\helpers\StringHelper
swapCase() Returns a case swapped version of the string. craft\helpers\StringHelper
titleize() Returns a trimmed string with the first letter of each word capitalized. Ignores the case of other letters, preserving any acronyms. Also accepts an array, $ignore, allowing you to list words not to be capitalized. craft\helpers\StringHelper
toAscii() Returns an ASCII version of the string. A set of non-ASCII characters are replaced with their closest ASCII counterparts, and the rest are removed. craft\helpers\StringHelper
toCamelCase() CamelCases a string. craft\helpers\StringHelper
toKebabCase() Kebab-cases a string. craft\helpers\StringHelper
toLowerCase() Converts all characters in the string to lowercase. An alias for PHP's mb_strtolower(). craft\helpers\StringHelper
toPascalCase() PascalCases a string. craft\helpers\StringHelper
toSnakeCase() Snake_cases a string. craft\helpers\StringHelper
toString() Converts an object to its string representation. If the object is an array, will glue the array elements togeter with the $glue param. Otherwise will cast the object to a string. craft\helpers\StringHelper
toTitleCase() Converts the first character of each word in the string to uppercase. craft\helpers\StringHelper
toUpperCase() Converts all characters in the string to uppercase. An alias for PHP's mb_strtoupper(). craft\helpers\StringHelper
trim() Returns the trimmed string. An alias for PHP's trim() function. craft\helpers\StringHelper
truncate() Truncates a string to the number of characters specified. yii\helpers\BaseStringHelper
truncateWords() Truncates a string to the number of words specified. yii\helpers\BaseStringHelper
upperCaseFirst() Converts the first character of the supplied string to uppercase. craft\helpers\StringHelper
Protected Methods
Method Description Defined By
truncateHtml() Truncate a string while preserving the HTML. yii\helpers\BaseStringHelper
Constants
Constant Value Description Defined By
UTF8 'UTF-8' craft\helpers\StringHelper

Method Details

UUID() public static method #

Generates a valid v4 UUID string. See [http://stackoverflow.com/a/2040279/684]

public static string UUID ( )
return string The UUID.

asciiCharMap() public static method #

Returns ASCII character mappings, merging in any custom defined mappings from the 'customAsciiCharMappings' config setting.

public static array asciiCharMap ( )
return array The fully merged ASCII character mappings.

camelCase() public static method #

Returns a camelCase version of the given string. Trims surrounding spaces, capitalizes letters following digits, spaces, dashes and underscores, and removes spaces, dashes, as well as underscores.

public static string camelCase ( \craft\helpers\string $str )
$str string The string to convert to camelCase.
return string The string in camelCase.

charAt() public static method #

Returns the character at a specific point in a potentially multibyte string.

public static string charAt ( \craft\helpers\string $str, \craft\helpers\int $i )
$str string The string to check.
$i integer The 0-offset position in the string to check.

charsAsArray() public static method #

Returns an array consisting of the characters in the string.

public static string[] charsAsArray ( \craft\helpers\string $str )
$str string
return string[] An array of string chars

collapseWhitespace() public static method #

Trims the string and replaces consecutive whitespace characters with a single space. This includes tabs and newline characters, as well as multibyte whitespace such as the thin space and ideographic space.

public static string collapseWhitespace ( \craft\helpers\string $str )
$str string The string to the whitespace from.
return string The trimmed string with condensed whitespace

contains() public static method #

Returns true if the string contains $needle, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.

public static boolean contains ( \craft\helpers\string $haystack, \craft\helpers\string $needle, \craft\helpers\bool $caseSensitive true )
$haystack string The string being checked.
$needle string The substring to look for.
$caseSensitive boolean Whether or not to force case-sensitivity.
return boolean Whether or not $haystack contains $needle.

containsAll() public static method #

Returns true if the string contains all $needles, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.

public static boolean containsAll ( \craft\helpers\string $haystack, array $needles, \craft\helpers\bool $caseSensitive true )
$haystack string The string being checked.
$needles array The substrings to look for.
$caseSensitive boolean Whether or not to force case-sensitivity.
return boolean Whether or not $haystack contains all $needles.

containsAny() public static method #

Returns true if the string contains any $needles, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.

public static boolean containsAny ( \craft\helpers\string $haystack, array $needles, \craft\helpers\bool $caseSensitive true )
$haystack string The string being checked.
$needles array The substrings to look for.
$caseSensitive boolean Whether or not to force case-sensitivity.
return boolean Whether or not $haystack contains any $needles.

containsMb4() public static method #

Detects whether the given string has any 4-byte UTF-8 characters.

public static boolean containsMb4 ( \craft\helpers\string $string )
$string string

convertToUtf8() public static method #

Attempts to convert a string to UTF-8 and clean any non-valid UTF-8 characters.

public static string convertToUtf8 ( \craft\helpers\string $string )
$string string

countSubstrings() public static method #

Returns the number of occurrences of $substring in the given string. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.

public static integer countSubstrings ( \craft\helpers\string $str, \craft\helpers\string $substring, \craft\helpers\bool $caseSensitive true )
$str string The string to search through.
$substring string The substring to search for.
$caseSensitive boolean Whether or not to enforce case-sensitivity
return integer The number of $substring occurrences.

decdec() public static method #

Base64-decodes and decrypts a string generated by encenc().

public static string decdec ( \craft\helpers\string $str )
$str string The string.

delimit() public static method #

Returns a lowercase and trimmed string separated by the given delimiter. Delimiters are inserted before uppercase characters (with the exception of the first character of the string), and in place of spaces, dashes, and underscores. Alpha delimiters are not converted to lowercase.

public static string delimit ( \craft\helpers\string $str, \craft\helpers\string $delimiter )
$str string The string to delimit.
$delimiter string Sequence used to separate parts of the string
return string The delimited string.

encenc() public static method #

Encrypts and base64-encodes a string.

See also decdec().

public static string encenc ( \craft\helpers\string $str )
$str string The string

encodeMb4() public static method #

HTML-encodes any 4-byte UTF-8 characters.

See also http://stackoverflow.com/a/16496730/1688568.

public static string encodeMb4 ( \craft\helpers\string $string )
$string string The string
return string The string with converted 4-byte UTF-8 characters

encoding() public static method #

Gets the current encoding of the given string.

public static string encoding ( \craft\helpers\string $string )
$string string

endsWith() public static method #

Returns true if the string ends with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.

public static boolean endsWith ( $str, $substring, $caseSensitive true )
$str string The string to check the end of.
$substring string The substring to look for.
$caseSensitive boolean Whether or not to force case-sensitivity.
return boolean Whether or not $str ends with $substring.

ensureLeft() public static method #

Ensures that the string begins with $substring. If it doesn't, it's prepended.

public static string ensureLeft ( \craft\helpers\string $str, \craft\helpers\string $substring )
$str string The string to modify.
$substring string The substring to add if not present.
return string The string prefixed by the $substring.

ensureRight() public static method #

Ensures that the string ends with $substring. If it doesn't, it's appended.

public static string ensureRight ( \craft\helpers\string $str, \craft\helpers\string $substring )
$str string The string to modify.
$substring string The substring to add if not present.
return string The string suffixed by the $substring.

first() public static method #

Returns the first $n characters of the string.

public static string first ( \craft\helpers\string $str, \craft\helpers\int $number )
$str string The string from which to get the substring.
$number integer The Number of chars to retrieve from the start.
return string The first $number characters.

hasLowerCase() public static method #

Returns whether the given string has any lowercase characters in it.

public static boolean hasLowerCase ( \craft\helpers\string $str )
$str string The string to check.

hasUpperCase() public static method #

Returns whether the given string has any uppercase characters in it.

public static boolean hasUpperCase ( \craft\helpers\string $str )
$str string The string to check.

indexOf() public static method #

Returns the index of the first occurrence of $needle in the string, and false if not found.

Accepts an optional offset from which to begin the search.

public static integer, boolean indexOf ( $str, $needle, $offset 0 )
$str string The string to check the index of.
$needle string The substring to look for.
$offset integer The offset from which to search.
return integer, boolean The occurrence's index if found, otherwise false.

indexOfLast() public static method #

Returns the index of the last occurrence of $needle in the string,and false if not found.

Accepts an optional offset from which to begin the search. Offsets may be negative to count from the last character in the string.

public static integer, boolean indexOfLast ( $str, $needle, $offset 0 )
$str string The string to check the last index of.
$needle string The substring to look for.
$offset integer The offset from which to search.
return integer, boolean The occurrence's last index if found, otherwise false.

insert() public static method #

Inserts $substring into the string at the $index provided.

public static string insert ( \craft\helpers\string $str, \craft\helpers\string $substring, \craft\helpers\int $index )
$str string The string to insert into.
$substring string The string to be inserted.
$index integer The 0-based index at which to insert the substring.
return string The resulting string after the insertion

isAlpha() public static method #

Returns true if the string contains only alphabetic chars, false otherwise.

public static boolean isAlpha ( \craft\helpers\string $str )
$str string The string to check.
return boolean Whether or not $str contains only alphabetic chars.

isAlphanumeric() public static method #

Returns true if the string contains only alphabetic and numeric chars, false otherwise.

public static boolean isAlphanumeric ( \craft\helpers\string $str )
$str string The string to check.
return boolean Whether or not $str contains only alphanumeric chars.

isHexadecimal() public static method #

Returns true if the string contains only hexadecimal chars, false otherwise.

public static boolean isHexadecimal ( \craft\helpers\string $str )
$str string The string to check.
return boolean Whether or not $str contains only hexadecimal characters

isLowerCase() public static method #

Returns true if the string contains only lowercase chars, false otherwise.

public static boolean isLowerCase ( \craft\helpers\string $str )
$str string The string to check.
return boolean Whether or not $str contains only lowercase characters.

isUUID() public static method #

Returns is the given string matches a v4 UUID pattern.

public static boolean isUUID ( \craft\helpers\string $uuid )
$uuid string The string to check.
return boolean Whether the string matches a v4 UUID pattern.

isUpperCase() public static method #

Returns true if the string contains only uppercase chars, false otherwise.

public static boolean isUpperCase ( \craft\helpers\string $str )
$str string The string to check.
return boolean Whether or not $str contains only uppercase characters.

isUtf8() public static method #

Checks if the given string is UTF-8 encoded.

public static boolean isUtf8 ( \craft\helpers\string $string )
$string string The string to check.

isWhitespace() public static method #

Returns true if the string contains only whitespace chars, false otherwise.

public static boolean isWhitespace ( \craft\helpers\string $str )
$str string The string to check.
return boolean Whether or not $str contains only whitespace characters.

last() public static method #

Returns the last $number characters of the string.

public static string last ( \craft\helpers\string $str, \craft\helpers\int $number )
$str string The string from which to get the substring.
$number integer The Number of chars to retrieve from the end.
return string The last $number characters.

length() public static method #

Returns the length of the string. An alias for PHP's mb_strlen() function.

public static integer length ( \craft\helpers\string $str )
$str string The string to get the length of.
return integer The number of characters in $str.

lines() public static method #

Splits on newlines and carriage returns, returning an array of strings corresponding to the lines in the string.

public static string[] lines ( \craft\helpers\string $str )
$str string The string to split.
return string[] An array of strings.

lowercaseFirst() public static method #

Converts the first character of the supplied string to lower case.

public static string lowercaseFirst ( \craft\helpers\string $str )
$str string The string to modify.
return string The string with the first character converted to lowercase.

padBoth() public static method #

Returns a new string of a given length such that both sides of the string are padded.

public static string padBoth ( $str, $length, $padStr ' ' )
$str string The string to pad.
$length integer The desired string length after padding.
$padStr string The string used to pad, defaults to space.
return string The padded string.

padLeft() public static method #

Returns a new string of a given length such that the beginning of the string is padded.

public static string padLeft ( \craft\helpers\string $str, \craft\helpers\int $length, \craft\helpers\string $padStr ' ' )
$str string The string to pad.
$length integer The desired string length after padding.
$padStr string The string used to pad, defaults to space.
return string The padded string.

padRight() public static method #

Returns a new string of a given length such that the end of the string is padded.

public static string padRight ( \craft\helpers\string $str, \craft\helpers\int $length, \craft\helpers\string $padStr ' ' )
$str string The string to pad.
$length integer The desired string length after padding.
$padStr string The string used to pad, defaults to space.
return string The padded string.

randomString() public static method #

Generates a random string of latin alphanumeric characters that defaults to a $length of 36. If $extendedChars is set to true, additional symbols can be included in the string. Note that the generated string is not a cryptographically secure string. If you need a cryptographically secure string, use Craft::$app->security->generateRandomString().

public static string randomString ( \craft\helpers\int $length 36, \craft\helpers\bool $extendedChars false )
$length integer The length of the random string. Defaults to 36.
$extendedChars boolean Whether to include symbols in the random string.
return string The randomly generated string.

randomStringWithChars() public static method #

Generates a random string of characters. Note that the generated string is not a cryptographically secure string. If you need a cryptographically secure string, use Craft::$app->security->generateRandomString().

public static string randomStringWithChars ( \craft\helpers\string $validChars, \craft\helpers\int $length )
$validChars string A string containing the valid characters
$length integer The length of the random string
return string The randomly generated string.

regexReplace() public static method #

Replaces all occurrences of $pattern in $str by $replacement. An alias for mb_ereg_replace().

public static string regexReplace ( \craft\helpers\string $str, \craft\helpers\string $pattern, \craft\helpers\string $replacement, \craft\helpers\string $options 'msr' )
$str string The haystack to search through.
$pattern string The regular expression pattern.
$replacement string The string to replace with.
$options string Matching conditions to be used. Defaults to 'msr'. See here for all options.
return string The resulting string after the replacements.

removeLeft() public static method #

Returns a new string with the prefix $substring removed, if present.

public static string removeLeft ( \craft\helpers\string $str, \craft\helpers\string $substring )
$str string The string from which to remove the prefix.
$substring string The prefix to remove.
return string The string without the prefix $substring.

removeRight() public static method #

Returns a new string with the suffix $substring removed, if present.

public static string removeRight ( \craft\helpers\string $str, \craft\helpers\string $substring )
$str string The string from which to remove the suffix.
$substring string The suffix to remove.
return string The string without the suffix $substring.

replace() public static method #

Replaces all occurrences of $search in $str by $replacement.

public static string replace ( \craft\helpers\string $str, \craft\helpers\string $search, \craft\helpers\string $replacement )
$str string The haystack to search through.
$search string The needle to search for.
$replacement string The string to replace with.
return string The resulting string after the replacements.

reverse() public static method #

Returns a reversed string. A multibyte version of strrev().

public static string reverse ( \craft\helpers\string $str )
$str string The string to reverse.
return string The reversed string.

safeTruncate() public static method #

Truncates the string to a given length, while ensuring that it does not split words. If $substring is provided, and truncating occurs, the string is further truncated so that the substring may be appended without exceeding t he desired length.

public static string safeTruncate ( \craft\helpers\string $str, \craft\helpers\int $length, \craft\helpers\string $substring '' )
$str string The string to truncate.
$length integer The desired length of the truncated string.
$substring string The substring to append if it can fit.
return string The resulting string after truncating.

split() public static method #

Splits a string into chunks on a given delimiter.

public static string[] split ( \craft\helpers\string $string, \craft\helpers\string $delimiter ',' )
$string string The string
$delimiter string The delimiter to split the string on (defaults to a comma)
return string[] The segments of the string

splitOnWords() public static method #

Splits a string into an array of the words in the string.

public static string[] splitOnWords ( \craft\helpers\string $string )
$string string The string
return string[] The words in the string

startsWith() public static method #

Returns true if the string begins with $substring, false otherwise. By default, the comparison is case-sensitive, but can be made insensitive by setting $caseSensitive to false.

public static boolean startsWith ( $str, $substring, $caseSensitive true )
$str string The string to check the start of.
$substring string The substring to look for.
$caseSensitive boolean Whether or not to enforce case-sensitivity.
return boolean Whether or not $str starts with $substring.

stripHtml() public static method #

Strips HTML tags out of a given string.

public static string stripHtml ( \craft\helpers\string $str )
$str string The string.
return string The string, sans-HTML

substr() public static method #

Returns the substring beginning at $start with the specified|null $length. It differs from the mb_substr() function in that providing a|null $length of null will return the rest of the string, rather than an empty string.

public static string substr ( \craft\helpers\string $str, \craft\helpers\int $start, \craft\helpers\int $length null )
$str string The string to get the length of.
$start integer Position of the first character to use.
$length integer, null Maximum number of characters used.
return string The substring of $str.

swapCase() public static method #

Returns a case swapped version of the string.

public static string swapCase ( \craft\helpers\string $str )
$str string The string to swap case.
return string The string with each character's case swapped.

titleize() public static method #

Returns a trimmed string with the first letter of each word capitalized. Ignores the case of other letters, preserving any acronyms. Also accepts an array, $ignore, allowing you to list words not to be capitalized.

public static string titleize ( \craft\helpers\string $str, array $ignore null )
$str string The string to titleize.
$ignore array, null An array of words not to capitalize.
return string The titleized string.

toAscii() public static method #

Returns an ASCII version of the string. A set of non-ASCII characters are replaced with their closest ASCII counterparts, and the rest are removed.

public static string toAscii ( \craft\helpers\string $str )
$str string The string to convert.
return string The string that contains only ASCII characters.

toCamelCase() public static method #

CamelCases a string.

See also:

public static string toCamelCase ( \craft\helpers\string $string )
$string string The string

toKebabCase() public static method #

Kebab-cases a string.

See also:

public static string toKebabCase ( \craft\helpers\string $string, \craft\helpers\string $glue '-', \craft\helpers\bool $lower true, \craft\helpers\bool $removePunctuation true )
$string string The string
$glue string The string used to glue the words together (default is a hyphen)
$lower boolean Whether the string should be lowercased (default is true)
$removePunctuation boolean Whether punctuation marks should be removed (default is true)
return string The kebab-cased string

toLowerCase() public static method #

Converts all characters in the string to lowercase. An alias for PHP's mb_strtolower().

public static string toLowerCase ( \craft\helpers\string $str )
$str string The string to convert to lowercase.
return string The lowercase string.

toPascalCase() public static method #

PascalCases a string.

See also:

public static string toPascalCase ( \craft\helpers\string $string )
$string string The string

toSnakeCase() public static method #

Snake_cases a string.

See also:

public static string toSnakeCase ( \craft\helpers\string $string )
$string string The string

toString() public static method #

Converts an object to its string representation. If the object is an array, will glue the array elements togeter with the $glue param. Otherwise will cast the object to a string.

public static string toString ( $object, \craft\helpers\string $glue ',' )
$object mixed The object to convert to a string.
$glue string The glue to use if the object is an array.
return string The string representation of the object.

toTitleCase() public static method #

Converts the first character of each word in the string to uppercase.

public static string toTitleCase ( \craft\helpers\string $str )
$str string The string to convert case.
return string The title-cased string.

toUpperCase() public static method #

Converts all characters in the string to uppercase. An alias for PHP's mb_strtoupper().

public static string toUpperCase ( \craft\helpers\string $str )
$str string The string to convert to uppercase.
return string The uppercase string.

trim() public static method #

Returns the trimmed string. An alias for PHP's trim() function.

public static string trim ( \craft\helpers\string $str )
$str string The string to trim.
return string The trimmed $str.

upperCaseFirst() public static method #

Converts the first character of the supplied string to uppercase.

public static string upperCaseFirst ( \craft\helpers\string $str )
$str string The string to modify.
return string The string with the first character being uppercase.