PHP Class Contao\StringUtil

Usage: $short = StringUtil::substr($str, 32); $html = StringUtil::substrHtml($str, 32); $xhtml = StringUtil::toXhtml($html5);
Afficher le fichier Open project: contao/core-bundle Class Usage Examples

Protected Properties

Свойство Type Description
$arrSplitCache array Trimsplit cache

Méthodes publiques

Méthode Description
binToUuid ( string $data ) : string Get a UUID string from binary data
censor ( string $strString, mixed $varWords, string $strReplace = '' ) : string Censor a single word or an array of words within a string
convertEncoding ( string $str, string $to, string $from = null ) : string Convert the character encoding
decodeEntities ( string $strString, integer $strQuoteStyle = ENT_COMPAT, string $strCharset = null ) : string Decode all entities
deserialize ( mixed $varValue, boolean $blnForceArray = false ) : array | string | null Return an unserialized array or the argument
encodeEmail ( string $strString ) : string Encode all e-mail addresses within a string
extractEmail ( string $strString, string $strAllowedTags = '' ) : array Extract all e-mail addresses from a string
generateAlias ( string $strString ) : string Generate an alias from a string
highlight ( string $strString, string $strPhrase, string $strOpeningTag = '<strong>', string $strClosingTag = '</strong>' ) : string Highlight a phrase within a string
insertTagToSrc ( string $data ) : string Convert insert tags inside "src" attributes to file paths
parseSimpleTokens ( string $strString, array $arrData ) : string Parse simple tokens
resolveFlaggedUrl ( string &$url ) : stdClass Resolve a flagged URL such as assets/js/core.js|static|10184084
restoreBasicEntities ( string $strBuffer ) : string Restore basic entities
sanitizeFileName ( string $strName ) : string Sanitize a file name
specialchars ( string $strString, boolean $blnStripInsertTags = false ) : string Convert special characters to HTML entities preventing double conversions
splitCsv ( string $strString, string $strDelimiter = ',' ) : array Split a string of comma separated values
splitFriendlyEmail ( string $strEmail ) : array Split a friendly-name e-address and return name and e-mail as array
srcToInsertTag ( string $data ) : string Convert file paths inside "src" attributes to insert tags
standardize ( string $strString, boolean $blnPreserveUppercase = false ) : string Standardize a parameter (strip special characters and convert spaces)
stripInsertTags ( string $strString ) : string Remove Contao insert tags from a string
substr ( string $strString, integer $intNumberOfChars, string $strEllipsis = ' …' ) : string Shorten a string to a given number of characters
substrHtml ( string $strString, integer $intNumberOfChars ) : string Shorten a HTML string to a given number of characters
toHtml5 ( string $strString ) : string Convert a string to HTML5
toXhtml ( string $strString ) : string Convert a string to XHTML
trimsplit ( string $strPattern, string $strString ) : array Split a string into fragments, remove whitespace and return fragments as array
uuidToBin ( string $uuid ) : string Convert a UUID string to binary data
wordWrap ( string $strString, integer $strLength = 75, string $strBreak = " " ) : string Wrap words after a particular number of characers

Method Details

binToUuid() public static méthode

Get a UUID string from binary data
public static binToUuid ( string $data ) : string
$data string The binary data
Résultat string The UUID string

censor() public static méthode

Censor a single word or an array of words within a string
public static censor ( string $strString, mixed $varWords, string $strReplace = '' ) : string
$strString string The string to censor
$varWords mixed A string or array or words to replace
$strReplace string An optional replacement string
Résultat string The cleaned string

convertEncoding() public static méthode

Convert the character encoding
public static convertEncoding ( string $str, string $to, string $from = null ) : string
$str string The input string
$to string The target character set
$from string An optional source character set
Résultat string The converted string

decodeEntities() public static méthode

Decode all entities
public static decodeEntities ( string $strString, integer $strQuoteStyle = ENT_COMPAT, string $strCharset = null ) : string
$strString string The string to decode
$strQuoteStyle integer The quote style (defaults to ENT_COMPAT)
$strCharset string An optional charset
Résultat string The decoded string

deserialize() public static méthode

Return an unserialized array or the argument
public static deserialize ( mixed $varValue, boolean $blnForceArray = false ) : array | string | null
$varValue mixed The serialized string
$blnForceArray boolean True to always return an array
Résultat array | string | null The array, an empty string or null

encodeEmail() public static méthode

Encode all e-mail addresses within a string
public static encodeEmail ( string $strString ) : string
$strString string The string to encode
Résultat string The encoded string

extractEmail() public static méthode

Extract all e-mail addresses from a string
public static extractEmail ( string $strString, string $strAllowedTags = '' ) : array
$strString string The string
$strAllowedTags string A list of allowed HTML tags
Résultat array The e-mail addresses

generateAlias() public static méthode

Generate an alias from a string
public static generateAlias ( string $strString ) : string
$strString string The string
Résultat string The alias

highlight() public static méthode

Highlight a phrase within a string
public static highlight ( string $strString, string $strPhrase, string $strOpeningTag = '<strong>', string $strClosingTag = '</strong>' ) : string
$strString string The string
$strPhrase string The phrase to highlight
$strOpeningTag string The opening tag (defaults to )
$strClosingTag string The closing tag (defaults to )
Résultat string The highlighted string

insertTagToSrc() public static méthode

Convert insert tags inside "src" attributes to file paths
public static insertTagToSrc ( string $data ) : string
$data string The markup string
Résultat string The markup with insert tags converted to file paths

parseSimpleTokens() public static méthode

Parse simple tokens
public static parseSimpleTokens ( string $strString, array $arrData ) : string
$strString string The string to be parsed
$arrData array The replacement data
Résultat string The converted string

resolveFlaggedUrl() public static méthode

Resolve a flagged URL such as assets/js/core.js|static|10184084
public static resolveFlaggedUrl ( string &$url ) : stdClass
$url string The URL
Résultat stdClass The options object

restoreBasicEntities() public static méthode

Restore basic entities
public static restoreBasicEntities ( string $strBuffer ) : string
$strBuffer string The string with the tags to be replaced
Résultat string The string with the original entities

sanitizeFileName() public static méthode

Sanitize a file name
public static sanitizeFileName ( string $strName ) : string
$strName string The file name
Résultat string The sanitized file name

specialchars() public static méthode

Convert special characters to HTML entities preventing double conversions
public static specialchars ( string $strString, boolean $blnStripInsertTags = false ) : string
$strString string The input string
$blnStripInsertTags boolean True to strip insert tags
Résultat string The converted string

splitCsv() public static méthode

Split a string of comma separated values
public static splitCsv ( string $strString, string $strDelimiter = ',' ) : array
$strString string The string to split
$strDelimiter string An optional delimiter
Résultat array The string chunks

splitFriendlyEmail() public static méthode

Split a friendly-name e-address and return name and e-mail as array
public static splitFriendlyEmail ( string $strEmail ) : array
$strEmail string A friendly-name e-mail address
Résultat array An array with name and e-mail address

srcToInsertTag() public static méthode

Convert file paths inside "src" attributes to insert tags
public static srcToInsertTag ( string $data ) : string
$data string The markup string
Résultat string The markup with file paths converted to insert tags

standardize() public static méthode

Standardize a parameter (strip special characters and convert spaces)
public static standardize ( string $strString, boolean $blnPreserveUppercase = false ) : string
$strString string The input string
$blnPreserveUppercase boolean True to preserver uppercase characters
Résultat string The converted string

stripInsertTags() public static méthode

Remove Contao insert tags from a string
public static stripInsertTags ( string $strString ) : string
$strString string The input string
Résultat string The converted string

substr() public static méthode

The function preserves words, so the result might be a bit shorter or longer than the number of characters given. It strips all tags.
public static substr ( string $strString, integer $intNumberOfChars, string $strEllipsis = ' …' ) : string
$strString string The string to shorten
$intNumberOfChars integer The target number of characters
$strEllipsis string An optional ellipsis to append to the shortened string
Résultat string The shortened string

substrHtml() public static méthode

The function preserves words, so the result might be a bit shorter or longer than the number of characters given. It preserves allowed tags.
public static substrHtml ( string $strString, integer $intNumberOfChars ) : string
$strString string The string to shorten
$intNumberOfChars integer The target number of characters
Résultat string The shortened HTML string

toHtml5() public static méthode

Convert a string to HTML5
public static toHtml5 ( string $strString ) : string
$strString string The XHTML string
Résultat string The HTML5 string

toXhtml() public static méthode

Convert a string to XHTML
public static toXhtml ( string $strString ) : string
$strString string The HTML5 string
Résultat string The XHTML string

trimsplit() public static méthode

Split a string into fragments, remove whitespace and return fragments as array
public static trimsplit ( string $strPattern, string $strString ) : array
$strPattern string The split pattern
$strString string The input string
Résultat array The fragments array

uuidToBin() public static méthode

Convert a UUID string to binary data
public static uuidToBin ( string $uuid ) : string
$uuid string The UUID string
Résultat string The binary data

wordWrap() public static méthode

Wrap words after a particular number of characers
public static wordWrap ( string $strString, integer $strLength = 75, string $strBreak = " " ) : string
$strString string The string to wrap
$strLength integer The number of characters to wrap after
$strBreak string An optional break character
Résultat string The wrapped string

Property Details

$arrSplitCache protected_oe static_oe property

Trimsplit cache
protected static array $arrSplitCache
Résultat array