Contao Utils Bundle

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'

Properties

$framework  : ContaoFrameworkInterface

Methods

__construct()  : mixed
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.
endsWith()  : bool
Check for the occurrence at the end of the string.
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.
startsWith()  : bool
Check for the occurrence at the start of the string.
truncateHtml()  : string
Truncates the text of a html string. By default, the last word is kept complete.

Constants

CAPITAL_LETTERS

public mixed CAPITAL_LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

CAPITAL_LETTERS_NONAMBIGUOUS

public mixed CAPITAL_LETTERS_NONAMBIGUOUS = 'ABCDEFGHJKLMNPQRSTUVWX'

NUMBERS_NONAMBIGUOUS

public mixed NUMBERS_NONAMBIGUOUS = '23456789'

SMALL_LETTERS

public mixed SMALL_LETTERS = 'abcdefghijklmnopqrstuvwxyz'

SMALL_LETTERS_NONAMBIGUOUS

public mixed SMALL_LETTERS_NONAMBIGUOUS = 'abcdefghjkmnpqrstuvwx'

Properties

$framework

protected ContaoFrameworkInterface $framework

Methods

__construct()

public __construct(ContaoFrameworkInterface $framework) : mixed
Parameters
$framework : ContaoFrameworkInterface

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
string

camelCaseToSnake()

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
string

convertXmlToArray()

Convert an xml string to array.

public convertXmlToArray(string $xmlData) : array<string|int, mixed>|null
Parameters
$xmlData : string
Return values
array<string|int, mixed>|null

endsWith()

Check for the occurrence at the end of the string.

public endsWith(string $haystack, string $needle) : bool

Use str_ends_with instead

Parameters
$haystack : string

The string to search in

$needle : string

The needle

Return values
bool

pregReplaceLast()

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|null

random()

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
throws
UnexpectedValueException

if the return value of the random number generator is higher that string length (\strlen($charList) - 1)

Return values
string

randomChar()

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
string

randomLetter()

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
string

randomNumber()

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
string

removeLeadingString()

Remove a string from the beginning of $subject.

public removeLeadingString(string $string, string $subject[, array<string|int, mixed> $options = [] ]) : string|null

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|null

removeTrailingString()

Remove a string from the end of $subject.

public removeTrailingString(string $string, string $subject[, array<string|int, mixed> $options = [] ]) : string|null

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|null

startsWith()

Check for the occurrence at the start of the string.

public startsWith(mixed $haystack, mixed $needle) : bool

Use str_starts_with instead

Parameters
$haystack : mixed

string The string to search in

$needle : mixed

string The needle

Return values
bool

truncateHtml()

Truncates the text of a 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

Return values
string

        
On this page

Search results