Craft 2 Class Reference

Class StringHelper

Package
craft.app.helpers
Namespace
Craft
Inheritance
class StringHelper
Since
1.0
Source Code
craft/app/helpers/StringHelper.php

Class StringHelper

Public Methods
Method Description Defined By
UUID() StringHelper
arrayToString() Converts an array to a string. StringHelper
asciiString() Converts extended ASCII characters to ASCII. StringHelper
checkForIconv() Returns whether iconv is installed and not buggy. StringHelper
convertToUTF8() Attempts to convert a string to UTF-8 and clean any non-valid UTF-8 characters. StringHelper
decdec() Base64-decodes and decrypts a string generated by encenc(). StringHelper
encenc() Encrypts and base64-encodes a string. StringHelper
encodeMb4() HTML-encodes any 4-byte UTF-8 characters. StringHelper
escapeCommas() Backslash-escapes any commas in a given string. StringHelper
escapeRegexChars() StringHelper
getAsciiCharMap() Returns ASCII character mappings. StringHelper
getAsciiPunctuation() Returns the asciiPunctuation array. StringHelper
getCharAt() Returns the character at a specific point in a potentially multibyte string. StringHelper
getEncoding() Gets the current encoding of the given string. StringHelper
isNotNullOrEmpty() StringHelper
isNullOrEmpty() StringHelper
isUTF8() Checks if the given string is UTF-8 encoded. StringHelper
isUUID() Returns is the given string matches a UUID pattern. StringHelper
lowercaseFirst() Lowercases the first character of a multibyte string. StringHelper
normalizeKeywords() Normalizes search keywords. StringHelper
parseMarkdown() Runs a string through Markdown. StringHelper
parseMarkdownLine() Runs a string through Markdown, but removes any paragraph tags that get removed StringHelper
randomString() StringHelper
splitOnWords() Splits a string into an array of the words in the string. StringHelper
stripHtml() Strips HTML tags out of a given string. StringHelper
toCamelCase() camelCases a string. StringHelper
toKebabCase() kebab-cases a string. StringHelper
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}. StringHelper
toPascalCase() PascalCases a string. StringHelper
toSnakeCase() snake_cases a string. StringHelper
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}. StringHelper
uppercaseFirst() Uppercases the first character of a multibyte string. StringHelper

Method Details

UUID() public static method #

public static string UUID()
Returns string

arrayToString() public static method #

Converts an array to a string.

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

asciiString() public static method #

Converts extended ASCII characters to ASCII.

public static string asciiString(string $str)
$str string
Returns string

checkForIconv() public static method #

Returns whether iconv is installed and not buggy.

public static bool checkForIconv()
Returns bool

convertToUTF8() public static method #

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

public static bool|string convertToUTF8($string $string)
$string $string
Returns bool / string

decdec() public static method #

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

public static string decdec(string $str)
$str string The string.
Returns string

encenc() public static method #

Encrypts and base64-encodes a string.

public static string encenc(string $str)
$str string The string.
Returns string

encodeMb4() public static method #

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

public static string encodeMb4(string $string)
$string string The string
Returns string The string with converted 4-byte UTF-8 characters

escapeCommas() public static method #

Backslash-escapes any commas in a given string.

public static string escapeCommas(string $str)
$str string The string.
Returns string

escapeRegexChars() public static method #

public static mixed escapeRegexChars($string $string)
$string $string
Returns mixed

getAsciiCharMap() public static method #

Returns ASCII character mappings.

public static array getAsciiCharMap()
Returns array

getAsciiPunctuation() public static method #

Returns the asciiPunctuation array.

public static array getAsciiPunctuation()
Returns array

getCharAt() public static method #

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

public static string getCharAt(string $str, int $i)
$str string
$i int
Returns string

getEncoding() public static method #

Gets the current encoding of the given string.

public static string getEncoding(string $string)
$string string
Returns string

isNotNullOrEmpty() public static method #

public static bool isNotNullOrEmpty($value $value)
$value $value
Returns bool

isNullOrEmpty() public static method #

public static bool isNullOrEmpty($value $value)
$value $value
Returns bool

isUTF8() public static method #

Checks if the given string is UTF-8 encoded.

public static bool isUTF8($string $string)
$string $string The string to check.
Returns bool

isUUID() public static method #

Returns is the given string matches a UUID pattern.

public static bool isUUID($uuid $uuid)
$uuid $uuid
Returns bool

lowercaseFirst() public static method #

Lowercases the first character of a multibyte string.

public static string lowercaseFirst(string $string)
$string string The multibyte string.
Returns string The string with the first character converted to lowercase.

normalizeKeywords() public static method #

Normalizes search keywords.

public static string normalizeKeywords(string $str, array $ignore = array (
), bool $processCharMap = true)
$str string The dirty keywords.
$ignore array Ignore words to strip out.
$processCharMap bool
Returns string The cleansed keywords.

parseMarkdown() public static method #

Runs a string through Markdown.

public static string parseMarkdown(string $str)
$str string
Returns string

parseMarkdownLine() public static method #

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

public static string parseMarkdownLine(string $str)
$str string
Returns string

randomString() public static method #

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

splitOnWords() public static method #

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

public static string[] splitOnWords(string $string)
$string string The string
Returns string[]

stripHtml() public static method #

Strips HTML tags out of a given string.

public static string stripHtml(string $str)
$str string The string.
Returns string

toCamelCase() public static method #

camelCases a string.

public static string toCamelCase(string $string)
$string string The string
Returns string

toKebabCase() public static method #

kebab-cases a string.

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

toLowerCase() public static method #

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}.

public static string toLowerCase(string $string)
$string string
Returns string

toPascalCase() public static method #

PascalCases a string.

public static string toPascalCase(string $string)
$string string The string
Returns string

toSnakeCase() public static method #

snake_cases a string.

public static string toSnakeCase(string $string)
$string string The string
Returns string

toUpperCase() public static method #

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}.

public static string toUpperCase(string $string)
$string string
Returns string

uppercaseFirst() public static method #

Uppercases the first character of a multibyte string.

public static string uppercaseFirst(string $string)
$string string The multibyte string.
Returns string The string with the first character converted to upercase.