StringHelper
- Type
- Class
- Namespace
- Craft
- Inherits
- Craft\StringHelper
- Since
- 1.0
Class StringHelper
See also http://craftcms.com
View source (opens new window)
# Public Methods
Method | Description |
---|---|
UUID() | |
arrayToString() | Converts an array to a string. |
asciiString() | Converts extended ASCII characters to ASCII. |
checkForIconv() | Returns whether iconv is installed and not buggy. |
convertToUTF8() | Attempts to convert a string to UTF-8 and clean any non-valid UTF-8 characters. |
decdec() | Base64-decodes and decrypts a string generated by {@link encenc()}. |
encenc() | Encrypts and base64-encodes a string. |
encodeMb4() | HTML-encodes any 4-byte UTF-8 characters. |
escapeCommas() | Backslash-escapes any commas in a given string. |
escapeRegexChars() | |
getAsciiCharMap() | Returns ASCII character mappings. |
getAsciiPunctuation() | Returns the asciiPunctuation array. |
getCharAt() | Returns the character at a specific point in a potentially multibyte string. |
getEncoding() | Gets the current encoding of the given string. |
isNotNullOrEmpty() | |
isNullOrEmpty() | |
isUTF8() | Checks if the given string is UTF-8 encoded. |
isUUID() | Returns is the given string matches a UUID pattern. |
lowercaseFirst() | Lowercases the first character of a multibyte string. |
normalizeKeywords() | Normalizes search keywords. |
parseMarkdown() | Runs a string through Markdown. |
parseMarkdownLine() | Runs a string through Markdown, but removes any paragraph tags that get removed |
randomString() | |
splitOnWords() | Splits a string into an array of the words in the string. |
stripHtml() | Strips HTML tags out of a given string. |
toCamelCase() | CamelCases a string. |
toKebabCase() | Kebab-cases a string. |
toLowerCase() | Returns a multibyte aware lower-case version of a string. Note: Not using mb_strtoupper because of {@see https://bugs.php.net/bug.php?id=47742}. |
toPascalCase() | PascalCases a string. |
toSnakeCase() | Snake_cases a string. |
toUpperCase() | Returns a multibyte aware upper-case version of a string. Note: Not using mb_strtoupper because of {@see https://bugs.php.net/bug.php?id=47742}. |
uppercaseFirst() | Uppercases the first character of a multibyte string. |
# UUID()
Signature
public static string UUID ( )
# arrayToString()
Converts an array to a string.
View source (opens new window)
Arguments
$arr
(mixed
)$glue
(string (opens new window))
Returns
Signature
public static string arrayToString ( $arr, $glue = ',' )
# asciiString()
Converts extended ASCII characters to ASCII.
View source (opens new window)
Arguments
$str
(string (opens new window))
Returns
Signature
public static string asciiString ( $str )
# checkForIconv()
Signature
public static boolean checkForIconv ( )
# convertToUTF8()
Attempts to convert a string to UTF-8 and clean any non-valid UTF-8 characters.
View source (opens new window)
Arguments
$string
Returns
Signature
public static boolean, string convertToUTF8 ( $string )
# decdec()
Base64-decodes and decrypts a string generated by {@link encenc()}.
See also encenc() View source (opens new window)
Arguments
$str
(string (opens new window)) – The string.
Returns
Signature
public static string decdec ( $str )
# encenc()
Encrypts and base64-encodes a string.
See also decdec() View source (opens new window)
Arguments
$str
(string (opens new window)) – The string.
Returns
Signature
public static string encenc ( $str )
# encodeMb4()
HTML-encodes any 4-byte UTF-8 characters.
See also http://stackoverflow.com/a/16496730/1688568 View source (opens new window)
Arguments
$string
(string (opens new window)) – The string
Returns
string (opens new window) – The string with converted 4-byte UTF-8 characters
Signature
public static string encodeMb4 ( $string )
# escapeCommas()
Backslash-escapes any commas in a given string.
View source (opens new window)
Arguments
$str
(string (opens new window)) – The string.
Returns
Signature
public static string escapeCommas ( $str )
# escapeRegexChars()
Signature
public static mixed escapeRegexChars ( $string )
# getAsciiCharMap()
Signature
public static array getAsciiCharMap ( )
# getAsciiPunctuation()
Signature
public static array getAsciiPunctuation ( )
# getCharAt()
Returns the character at a specific point in a potentially multibyte string.
See also http://stackoverflow.com/questions/10360764/there-are-simple-way-to-get-a-character-from-multibyte-string-in-php View source (opens new window)
Arguments
$str
(string (opens new window))$i
(integer (opens new window))
Returns
Signature
public static string getCharAt ( $str, $i )
# getEncoding()
Gets the current encoding of the given string.
View source (opens new window)
Arguments
$string
(string (opens new window))
Returns
Signature
public static string getEncoding ( $string )
# isNotNullOrEmpty()
Signature
public static boolean isNotNullOrEmpty ( $value )
# isNullOrEmpty()
Signature
public static boolean isNullOrEmpty ( $value )
# isUTF8()
Checks if the given string is UTF-8 encoded.
View source (opens new window)
Arguments
$string
– The string to check.
Returns
Signature
public static boolean isUTF8 ( $string )
# isUUID()
Returns is the given string matches a UUID pattern.
View source (opens new window)
Arguments
$uuid
Returns
Signature
public static boolean isUUID ( $uuid )
# lowercaseFirst()
Lowercases the first character of a multibyte string.
View source (opens new window)
Arguments
$string
(string (opens new window)) – The multibyte string.
Returns
string (opens new window) – The string with the first character converted to lowercase.
Signature
public static string lowercaseFirst ( $string )
# normalizeKeywords()
Normalizes search keywords.
View source (opens new window)
Arguments
$str
(string (opens new window)) – The dirty keywords.$ignore
(array (opens new window)) – Ignore words to strip out.$processCharMap
(boolean (opens new window))
Returns
string (opens new window) – The cleansed keywords.
Signature
public static string normalizeKeywords ( $str, $ignore = [], $processCharMap = true )
# parseMarkdown()
Runs a string through Markdown.
View source (opens new window)
Arguments
$str
(string (opens new window))
Returns
Signature
public static string parseMarkdown ( $str )
# parseMarkdownLine()
Runs a string through Markdown, but removes any paragraph tags that get removed
View source (opens new window)
Arguments
$str
(string (opens new window))
Returns
Signature
public static string parseMarkdownLine ( $str )
# randomString()
View source (opens new window)
Arguments
$length
(integer (opens new window))$extendedChars
(boolean (opens new window))
Returns
Signature
public static string randomString ( $length = 36, $extendedChars = false )
# splitOnWords()
Splits a string into an array of the words in the string.
View source (opens new window)
Arguments
$string
(string (opens new window)) – The string
Returns
Signature
public static string[] splitOnWords ( $string )
# stripHtml()
Strips HTML tags out of a given string.
View source (opens new window)
Arguments
$str
(string (opens new window)) – The string.
Returns
Signature
public static string stripHtml ( $str )
# toCamelCase()
CamelCases a string.
See also:
View source (opens new window)
Arguments
$string
(string (opens new window)) – The string
Returns
Signature
public static string toCamelCase ( $string )
# toKebabCase()
Kebab-cases a string.
See also:
View source (opens new window)
Arguments
$string
(string (opens new window)) – The string$glue
(string (opens new window)) – The string used to glue the words together (default is a hyphen)$lower
(boolean (opens new window)) – Whether the string should be lowercased (default is true)$removePunctuation
(boolean (opens new window)) – Whether punctuation marks should be removed (default is true)
Returns
Signature
public static string toKebabCase ( $string, $glue = '-', $lower = true, $removePunctuation = true )
# toLowerCase()
Returns a multibyte aware lower-case version of a string. Note: Not using mb_strtoupper because of {@see https://bugs.php.net/bug.php?id=47742}.
View source (opens new window)
Arguments
$string
(string (opens new window))
Returns
Signature
public static string toLowerCase ( $string )
# toPascalCase()
PascalCases a string.
See also:
View source (opens new window)
Arguments
$string
(string (opens new window)) – The string
Returns
Signature
public static string toPascalCase ( $string )
# toSnakeCase()
Snake_cases a string.
See also:
View source (opens new window)
Arguments
$string
(string (opens new window)) – The string
Returns
Signature
public static string toSnakeCase ( $string )
# toUpperCase()
Returns a multibyte aware upper-case version of a string. Note: Not using mb_strtoupper because of {@see https://bugs.php.net/bug.php?id=47742}.
View source (opens new window)
Arguments
$string
(string (opens new window))
Returns
Signature
public static string toUpperCase ( $string )
# uppercaseFirst()
Uppercases the first character of a multibyte string.
View source (opens new window)
Arguments
$string
(string (opens new window)) – The multibyte string.
Returns
string (opens new window) – The string with the first character converted to upercase.
Signature
public static string uppercaseFirst ( $string )
# Constants
Constant | Description |
---|---|
UTF8 |