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

Returns

string (opens new window)

Signature

public static string arrayToString ( $arr, $glue = ',' )

# asciiString()

Converts extended ASCII characters to ASCII.

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public static string asciiString ( $str )

# checkForIconv()

Returns whether iconv is installed and not buggy.

View source (opens new window)

Returns

boolean (opens new window)

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

boolean (opens new window), string (opens new window)

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

Returns

string (opens new window)

Signature

public static string decdec ( $str )

# encenc()

Encrypts and base64-encodes a string.

See also decdec() View source (opens new window)

Arguments

Returns

string (opens new window)

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

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

Returns

string (opens new window)

Signature

public static string escapeCommas ( $str )

# escapeRegexChars()

View source (opens new window)

Arguments

  • $string

Returns

mixed

Signature

public static mixed escapeRegexChars ( $string )

# getAsciiCharMap()

Returns ASCII character mappings.

View source (opens new window)

Returns

array (opens new window)

Signature

public static array getAsciiCharMap ( )

# getAsciiPunctuation()

Returns the asciiPunctuation array.

View source (opens new window)

Returns

array (opens new window)

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

Returns

string (opens new window)

Signature

public static string getCharAt ( $str, $i )

# getEncoding()

Gets the current encoding of the given string.

View source (opens new window)

Arguments

Returns

string (opens new window)

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

boolean (opens new window)

Signature

public static boolean isUTF8 ( $string )

# isUUID()

Returns is the given string matches a UUID pattern.

View source (opens new window)

Arguments

  • $uuid

Returns

boolean (opens new window)

Signature

public static boolean isUUID ( $uuid )

# lowercaseFirst()

Lowercases the first character of a multibyte string.

View source (opens new window)

Arguments

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

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

Returns

string (opens new window)

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

Returns

string (opens new window)

Signature

public static string parseMarkdownLine ( $str )

# randomString()

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

Returns

string (opens new window)[]

Signature

public static string[] splitOnWords ( $string )

# stripHtml()

Strips HTML tags out of a given string.

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public static string stripHtml ( $str )

# toCamelCase()

Signature

public static string toCamelCase ( $string )

# toKebabCase()

Kebab-cases a string.

See also:

View source (opens new window)

Arguments

Returns

string (opens new window)

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

Returns

string (opens new window)

Signature

public static string toLowerCase ( $string )

# toPascalCase()

PascalCases a string.

See also:

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public static string toPascalCase ( $string )

# toSnakeCase()

Snake_cases a string.

See also:

View source (opens new window)

Arguments

Returns

string (opens new window)

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

Returns

string (opens new window)

Signature

public static string toUpperCase ( $string )

# uppercaseFirst()

Uppercases the first character of a multibyte string.

View source (opens new window)

Arguments

Returns

string (opens new window) – The string with the first character converted to upercase.

Signature

public static string uppercaseFirst ( $string )

# Constants

Constant Description
UTF8