StringHelper

Type
Class
Namespace
Craft
Inherits
Craft\StringHelper
Since
1.0

Class StringHelper

See also http://craftcms.com

View source

Public Methods

MethodDescription
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

Arguments

Returns

string

Signature

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

asciiString()

Converts extended ASCII characters to ASCII.

View source

Arguments

Returns

string

Signature

public static string asciiString ( $str )

checkForIconv()

Returns whether iconv is installed and not buggy.

View source

Returns

boolean

Signature

public static boolean checkForIconv ( )

convertToUTF8()

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

View source

Arguments

  • $string

Returns

boolean, string

Signature

public static boolean, string convertToUTF8 ( $string )

decdec()

Base64-decodes and decrypts a string generated by {@link encenc()}.

See also encenc()View source

Arguments

Returns

string

Signature

public static string decdec ( $str )

encenc()

Encrypts and base64-encodes a string.

See also decdec()View source

Arguments

Returns

string

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

Arguments

  • $string (string) – The string

Returns

string – 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

Arguments

Returns

string

Signature

public static string escapeCommas ( $str )

escapeRegexChars()

View source

Arguments

  • $string

Returns

mixed

Signature

public static mixed escapeRegexChars ( $string )

getAsciiCharMap()

Returns ASCII character mappings.

View source

Returns

array

Signature

public static array getAsciiCharMap ( )

getAsciiPunctuation()

Returns the asciiPunctuation array.

View source

Returns

array

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

Arguments

Returns

string

Signature

public static string getCharAt ( $str, $i )

getEncoding()

Gets the current encoding of the given string.

View source

Arguments

Returns

string

Signature

public static string getEncoding ( $string )

isNotNullOrEmpty()

View source

Arguments

  • $value

Returns

boolean

Throws

Signature

public static boolean isNotNullOrEmpty ( $value )

isNullOrEmpty()

View source

Arguments

  • $value

Returns

boolean

Throws

Signature

public static boolean isNullOrEmpty ( $value )

isUTF8()

Checks if the given string is UTF-8 encoded.

View source

Arguments

  • $string – The string to check.

Returns

boolean

Signature

public static boolean isUTF8 ( $string )

isUUID()

Returns is the given string matches a UUID pattern.

View source

Arguments

  • $uuid

Returns

boolean

Signature

public static boolean isUUID ( $uuid )

lowercaseFirst()

Lowercases the first character of a multibyte string.

View source

Arguments

  • $string (string) – The multibyte string.

Returns

string – The string with the first character converted to lowercase.

Signature

public static string lowercaseFirst ( $string )

normalizeKeywords()

Normalizes search keywords.

View source

Arguments

  • $str (string) – The dirty keywords.
  • $ignore (array) – Ignore words to strip out.
  • $processCharMap (boolean)

Returns

string – The cleansed keywords.

Signature

public static string normalizeKeywords ( $str, $ignore = [], $processCharMap = true )

parseMarkdown()

Runs a string through Markdown.

View source

Arguments

Returns

string

Signature

public static string parseMarkdown ( $str )

parseMarkdownLine()

Runs a string through Markdown, but removes any paragraph tags that get removed

View source

Arguments

Returns

string

Signature

public static string parseMarkdownLine ( $str )

randomString()

View source

Arguments

Returns

string

Signature

public static string randomString ( $length = 36, $extendedChars = false )

splitOnWords()

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

View source

Arguments

  • $string (string) – The string

Returns

string[]

Signature

public static string[] splitOnWords ( $string )

stripHtml()

Strips HTML tags out of a given string.

View source

Arguments

Returns

string

Signature

public static string stripHtml ( $str )

toCamelCase()

CamelCases a string.

See also:

View source

Arguments

  • $string (string) – The string

Returns

string

Signature

public static string toCamelCase ( $string )

toKebabCase()

Kebab-cases a string.

See also:

View source

Arguments

  • $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)

Returns

string

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

Arguments

Returns

string

Signature

public static string toLowerCase ( $string )

toPascalCase()

PascalCases a string.

See also:

View source

Arguments

  • $string (string) – The string

Returns

string

Signature

public static string toPascalCase ( $string )

toSnakeCase()

Snake_cases a string.

See also:

View source

Arguments

  • $string (string) – The string

Returns

string

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

Arguments

Returns

string

Signature

public static string toUpperCase ( $string )

uppercaseFirst()

Uppercases the first character of a multibyte string.

View source

Arguments

  • $string (string) – The multibyte string.

Returns

string – The string with the first character converted to upercase.

Signature

public static string uppercaseFirst ( $string )

Constants

ConstantDescription
UTF8