Contao Utils Bundle

StringUtil
in package

Class StringUtil.

Use Utils service instead

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
$utils  : Utils

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.
convertToInlineCss()  : string
Convert css into inline styles.
convertXmlToArray()  : mixed
endsWith()  : bool
Check for the occurrence at the end of the string.
ensureLineBreaks()  : string
Ensure line breaks for several languages.
html2Text()  : string
Converts html to text.
lowerCase()  : string
Convenience method for lower casing in a save callback.
pregReplaceLast()  : mixed|string
random()  : mixed
randomChar()  : mixed
randomLetter()  : mixed
randomNumber()  : mixed
removeLeadingAndTrailingSlash()  : string
removeLeadingString()  : mixed
removeTrailingString()  : mixed
replaceInsertTags()  : string
Replace insert tags with their values.
replaceUnicodeEmojisByHtml()  : array<string|int, mixed>|string|array<string|int, string>|null
restoreBasicEntities()  : string
Restore basic entities.
startsWith()  : bool
Check for the occurrence at the start of the string.
truncateHtml()  : string
Truncates a given string respecting html element.

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, Utils $utils) : mixed
Parameters
$framework : ContaoFrameworkInterface
$utils : Utils

camelCaseToDashed()

Convert a camel case string to a dashed string.

public camelCaseToDashed(string $value) : string

Use utils service instead

Example: MyPrettyClass to my-pretty-class

Parameters
$value : string
Tags
codeCoverageIgnore
Return values
string

camelCaseToSnake()

Convert a camel case string to a snake cased string.

public camelCaseToSnake(string $value) : string

Use utils service instead

Example: MyPrettyClass to my_pretty_class

Parameters
$value : string
Tags
codeCoverageIgnore
Return values
string

convertToInlineCss()

Convert css into inline styles.

public convertToInlineCss(string $text[, array<string|int, mixed> $cssText = null ]) : string

Use CssInliner-Library directly in your code. We recommend tijsverkoyen/css-to-inline-styles (https://github.com/tijsverkoyen/CssToInlineStyles)

Parameters
$text : string
$cssText : array<string|int, mixed> = null

the css as text (no paths allowed atm)

Tags
codeCoverageIgnore
Return values
string

convertXmlToArray()

public convertXmlToArray(string $xmlData) : mixed

Use utils service instead

Parameters
$xmlData : string
Tags
codeCoverageIgnore

endsWith()

Check for the occurrence at the end of the string.

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

Use utils service instead

Parameters
$haystack : string

The string to search in

$needle : string

The needle

Tags
codeCoverageIgnore
Return values
bool

ensureLineBreaks()

Ensure line breaks for several languages.

public ensureLineBreaks(string $buffer[, string $language = 'en' ]) : string

use locale util of utils service instead

Parameters
$buffer : string
$language : string = 'en'
Return values
string

html2Text()

Converts html to text.

public html2Text(string $html[, array<string|int, mixed> $options = [] ]) : string

Use html2text-library direct in your code, we recommend html2text/html2text (https://github.com/mtibben/html2text)

Parameters
$html : string
$options : array<string|int, mixed> = []
Tags
throws
Html2TextException
codeCoverageIgnore
Return values
string

lowerCase()

Convenience method for lower casing in a save callback.

public lowerCase(mixed $value, DataContainer $objDc) : string

Deprecated in favor of custom callback that could be used with contao service callbacks

Parameters
$value : mixed
$objDc : DataContainer
Tags
codeCoverageIgnore
Return values
string

pregReplaceLast()

public pregReplaceLast(string $regExp, string $subject) : mixed|string

Use utils service instead

Parameters
$regExp : string
$subject : string
Tags
codeCoverageIgnore
Return values
mixed|string

random()

public random(string $charList) : mixed

Use utils service instead

Parameters
$charList : string
Tags
codeCoverageIgnore

randomChar()

public randomChar([bool $includeAmbiguousChars = false ]) : mixed

Use utils service instead

Parameters
$includeAmbiguousChars : bool = false
Tags
codeCoverageIgnore

randomLetter()

public randomLetter([bool $includeAmbiguousChars = false ]) : mixed

Use utils service instead

Parameters
$includeAmbiguousChars : bool = false
Tags
codeCoverageIgnore

randomNumber()

public randomNumber([bool $includeAmbiguousChars = false ]) : mixed

Use utils service instead

Parameters
$includeAmbiguousChars : bool = false
Tags
codeCoverageIgnore

removeLeadingAndTrailingSlash()

public removeLeadingAndTrailingSlash(string $string) : string

Use trim($string, "/") instead

Parameters
$string : string
Tags
codeCoverageIgnore
Return values
string

removeLeadingString()

public removeLeadingString(string $string, string $subject) : mixed

Use utils service instead

Parameters
$string : string
$subject : string
Tags
codeCoverageIgnore

removeTrailingString()

public removeTrailingString(string $string, string $subject) : mixed

Use utils service instead

Parameters
$string : string
$subject : string
Tags
codeCoverageIgnore

replaceInsertTags()

Replace insert tags with their values.

public replaceInsertTags(string $buffer[, bool $cache = true ]) : string

Use Controller::replaceInsertTags as adapter

Parameters
$buffer : string

The text with the tags to be replaced

$cache : bool = true

If false, non-cacheable tags will be replaced

Tags
codeCoverageIgnore
Return values
string

The text with the replaced tags

replaceUnicodeEmojisByHtml()

public replaceUnicodeEmojisByHtml(string|null $text) : array<string|int, mixed>|string|array<string|int, string>|null

Will be removed in version 3.0. Use elvanto/litemoji (https://github.com/elvanto/litemoji) instead.

Parameters
$text : string|null
Tags
codeCoverageIgnore
Return values
array<string|int, mixed>|string|array<string|int, string>|null

restoreBasicEntities()

Restore basic entities.

public restoreBasicEntities(string $string) : string

use \Contao\StringUtil::restoreBasicEntities() instead

Parameters
$string : string

The string with the tags to be replaced

Tags
codeCoverageIgnore
Return values
string

The string with the original entities

startsWith()

Check for the occurrence at the start of the string.

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

Use utils service instead

Parameters
$haystack : mixed

string The string to search in

$needle : mixed

string The needle

Tags
codeCoverageIgnore
Return values
bool

truncateHtml()

Truncates a given string respecting html element.

public truncateHtml(string $text[, int $length = 100 ][, string $ending = '&nbsp;&hellip;' ][, bool $exact = false ][, bool $considerHtml = true ]) : string

Use utils service instead

Parameters
$text : string
$length : int = 100
$ending : string = '&nbsp;&hellip;'
$exact : bool = false
$considerHtml : bool = true
Tags
codeCoverageIgnore
Return values
string

        
On this page

Search results