StringUtil
in package
Table of Contents
Constants
- CAPITAL_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- CAPITAL_LETTERS_NONAMBIGUOUS = 'ABCDEFGHJKLMNPQRSTUVWX'
- NUMBERS = '0123456789'
- NUMBERS_NONAMBIGUOUS = '23456789'
- SMALL_LETTERS = 'abcdefghijklmnopqrstuvwxyz'
- SMALL_LETTERS_NONAMBIGUOUS = 'abcdefghjkmnpqrstuvwx'
Methods
- camelCaseToDashed() : string
- Convert a camel case string to a dashed string.
- camelCaseToSnake() : string
- Convert a camel case string to a snake cased string.
- convertXmlToArray() : array<string|int, mixed>|null
- Convert an xml string to array.
- pregReplaceLast() : string|null
- Replace the last match of string with preg_replace.
- random() : string
- Return a random char of a given string.
- randomChar() : string
- Return a random char. Can be a letter or a number.
- randomLetter() : string
- Return a random letter char.
- randomNumber() : string
- Return a random number char.
- removeLeadingString() : string|null
- Remove a string from the beginning of $subject.
- removeTrailingString() : string|null
- Remove a string from the end of $subject.
- truncateHtml() : string
- Truncates the text of an HTML string. By default, the last word is kept complete.
Constants
CAPITAL_LETTERS
private
mixed
CAPITAL_LETTERS
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
CAPITAL_LETTERS_NONAMBIGUOUS
private
mixed
CAPITAL_LETTERS_NONAMBIGUOUS
= 'ABCDEFGHJKLMNPQRSTUVWX'
NUMBERS
private
mixed
NUMBERS
= '0123456789'
NUMBERS_NONAMBIGUOUS
private
mixed
NUMBERS_NONAMBIGUOUS
= '23456789'
SMALL_LETTERS
private
mixed
SMALL_LETTERS
= 'abcdefghijklmnopqrstuvwxyz'
SMALL_LETTERS_NONAMBIGUOUS
private
mixed
SMALL_LETTERS_NONAMBIGUOUS
= 'abcdefghjkmnpqrstuvwx'
Methods
camelCaseToDashed()
Convert a camel case string to a dashed string.
public
camelCaseToDashed(mixed $value) : string
Example: MyPrettyClass to my-pretty-class
Parameters
- $value : mixed
Return values
stringcamelCaseToSnake()
Convert a camel case string to a snake cased string.
public
camelCaseToSnake(string $value) : string
Example: MyPrettyClass to my_pretty_class
Parameters
- $value : string
Return values
stringconvertXmlToArray()
Convert an xml string to array.
public
convertXmlToArray(string $xmlData) : array<string|int, mixed>|null
Parameters
- $xmlData : string
Return values
array<string|int, mixed>|nullpregReplaceLast()
Replace the last match of string with preg_replace.
public
pregReplaceLast(string $regExp, string $subject[, string $replacement = '' ]) : string|null
Parameters
- $regExp : string
- $subject : string
- $replacement : string = ''
Return values
string|nullrandom()
Return a random char of a given string.
public
random(string $charList[, array<string|int, mixed> $options = [] ]) : string
Options:
- randomNumberGenerator: (callable) A custom callback function to generate a random number. Get min and max as parameter.
Parameters
- $charList : string
- $options : array<string|int, mixed> = []
Tags
Return values
stringrandomChar()
Return a random char. Can be a letter or a number.
public
randomChar([bool $includeAmbiguousChars = false ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $includeAmbiguousChars : bool = false
- $options : array<string|int, mixed> = []
-
Pass additional options. See self::random()
Return values
stringrandomLetter()
Return a random letter char.
public
randomLetter([bool $includeAmbiguousChars = false ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $includeAmbiguousChars : bool = false
- $options : array<string|int, mixed> = []
-
Pass additional options. See self::random()
Return values
stringrandomNumber()
Return a random number char.
public
randomNumber([bool $includeAmbiguousChars = false ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $includeAmbiguousChars : bool = false
- $options : array<string|int, mixed> = []
-
Pass additional options. See self::random()
Return values
stringremoveLeadingString()
Remove a string from the beginning of $subject.
public
removeLeadingString(string $string, string $subject[, array<string|int, mixed> $options = [] ]) : string|null
Replace with userland code. Will be removed in the next major version.
Options:
- trim: (bool) Trim whitespace from the beginning after a leading string is removed. Default true.
Parameters
- $string : string
- $subject : string
- $options : array<string|int, mixed> = []
Return values
string|nullremoveTrailingString()
Remove a string from the end of $subject.
public
removeTrailingString(string $string, string $subject[, array<string|int, mixed> $options = [] ]) : string|null
Replace with userland code. Will be removed in the next major version.
Options:
- trim: (bool) Trim whitespace from the end after a trailing string is removed. Default true.
Parameters
- $string : string
- $subject : string
- $options : array<string|int, mixed> = []
Return values
string|nulltruncateHtml()
Truncates the text of an HTML string. By default, the last word is kept complete.
public
truncateHtml(string $html, int $limit[, string $ellipsis = '…' ][, array<string|int, mixed> $options = [] ]) : string
Credits: https://www.pjgalbraith.com/truncating-text-html-with-php/
Additional options:
- exact: (bool) Cut text exact on character limit instead after the word
Parameters
- $html : string
-
The HTML string that should be truncated
- $limit : int
-
Max number of text characters (HTML tags are not counted)
- $ellipsis : string = '…'
-
Characters that should be displayed, where the string is truncated
- $options : array<string|int, mixed> = []
-
Additional Options