PHP Class Contao\StringUtil

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

Protected Properties

Property Type Description
$arrSplitCache array Trimsplit cache

Public Methods

Method 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 method

Get a UUID string from binary data
public static binToUuid ( string $data ) : string
$data string The binary data
return string The UUID string

censor() public static method

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
return string The cleaned string

convertEncoding() public static method

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
return string The converted string

decodeEntities() public static method

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
return string The decoded string

deserialize() public static method

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
return array | string | null The array, an empty string or null

encodeEmail() public static method

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

extractEmail() public static method

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
return array The e-mail addresses

generateAlias() public static method

Generate an alias from a string
public static generateAlias ( string $strString ) : string
$strString string The string
return string The alias

highlight() public static method

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 )
return string The highlighted string

insertTagToSrc() public static method

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

parseSimpleTokens() public static method

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

resolveFlaggedUrl() public static method

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

restoreBasicEntities() public static method

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

sanitizeFileName() public static method

Sanitize a file name
public static sanitizeFileName ( string $strName ) : string
$strName string The file name
return string The sanitized file name

specialchars() public static method

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
return string The converted string

splitCsv() public static method

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
return array The string chunks

splitFriendlyEmail() public static method

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
return array An array with name and e-mail address

srcToInsertTag() public static method

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

standardize() public static method

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
return string The converted string

stripInsertTags() public static method

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

substr() public static method

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
return string The shortened string

substrHtml() public static method

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
return string The shortened HTML string

toHtml5() public static method

Convert a string to HTML5
public static toHtml5 ( string $strString ) : string
$strString string The XHTML string
return string The HTML5 string

toXhtml() public static method

Convert a string to XHTML
public static toXhtml ( string $strString ) : string
$strString string The HTML5 string
return string The XHTML string

trimsplit() public static method

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
return array The fragments array

uuidToBin() public static method

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

wordWrap() public static method

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
return string The wrapped string

Property Details

$arrSplitCache protected static property

Trimsplit cache
protected static array $arrSplitCache
return array