PHP Class Neos\Eel\Helper\StringHelper

Inheritance: implements Neos\Eel\ProtectedContextAwareInterface
显示文件 Open project: neos/flow-development-collection Class Usage Examples

Public Methods

Method Description
allowsCallOfMethod ( string $methodName ) : boolean All methods are considered safe
charAt ( string $string, integer $index ) : string Get the character at a specific position
crop ( string $string, integer $maximumCharacters, string $suffix = '' ) : string Crop a string to maximumCharacters length, optionally appending suffix if cropping was necessary.
cropAtSentence ( string $string, integer $maximumCharacters, string $suffix = '' ) : string Crop a string to maximumCharacters length, taking sentences into account, optionally appending suffix if cropping was necessary.
cropAtWord ( string $string, integer $maximumCharacters, string $suffix = '' ) : string Crop a string to maximumCharacters length, taking words into account, optionally appending suffix if cropping was necessary.
endsWith ( string $string, string $search, integer $position = null ) : boolean Test if a string ends with the given search string
firstLetterToLowerCase ( string $string ) : string Lowercase the first letter of a string
firstLetterToUpperCase ( string $string ) : string Uppercase the first letter of a string
htmlSpecialChars ( string $string, boolean $preserveEntities = false ) : string Convert special characters to HTML entities
indexOf ( string $string, string $search, integer $fromIndex = null ) : integer Find the first position of a substring in the given string
isBlank ( string $string ) : boolean Test if the given string is blank (empty or consists of whitespace only)
lastIndexOf ( string $string, string $search, integer $toIndex = null ) : integer Find the last position of a substring in the given string
length ( string $string ) : integer Get the length of a string
md5 ( string $string ) : string Calculate the MD5 checksum of the given string
pregMatch ( string $string, string $pattern ) : array Match a string with a regular expression (PREG style)
pregReplace ( string $string, string $pattern, string $replace ) : string Replace occurrences of a search string inside the string using regular expression matching (PREG style)
pregSplit ( string $string, string $pattern, integer $limit = null ) : array Split a string by a separator using regular expression matching (PREG style)
rawUrlDecode ( string $string ) : string Decode the string from URLs according to RFC 3986
rawUrlEncode ( string $string ) : string Encode the string for URLs according to RFC 3986
replace ( string $string, string $search, string $replace ) : string Replace occurrences of a search string inside the string
split ( string $string, string $separator = null, integer $limit = null ) : array Split a string by a separator
startsWith ( string $string, string $search, integer $position = null ) : boolean Test if a string starts with the given search string
stripTags ( string $string, string $allowableTags = null ) : string Strip all HTML tags from the given string
substr ( string $string, integer $start, integer $length = null ) : string Return the characters in a string from start up to the given length
substring ( string $string, integer $start, integer $end = null ) : string Return the characters in a string from a start index to an end index
toBoolean ( string $string ) : boolean Convert a string to boolean
toFloat ( string $string ) : float Convert a string to float
toInteger ( string $string ) : integer Convert a string to integer
toLowerCase ( string $string ) : string Lowercase a string
toString ( mixed $value ) : string Convert the given value to a string
toUpperCase ( string $string ) : string Uppercase a string
trim ( string $string, string $charlist = null ) : string Trim whitespace at the beginning and end of a string

Method Details

allowsCallOfMethod() public method

All methods are considered safe
public allowsCallOfMethod ( string $methodName ) : boolean
$methodName string
return boolean

charAt() public method

Example:: String.charAt("abcdefg", 5) == "f"
public charAt ( string $string, integer $index ) : string
$string string The input string
$index integer The index to get
return string The character at the given index

crop() public method

Crop a string to maximumCharacters length, optionally appending suffix if cropping was necessary.
public crop ( string $string, integer $maximumCharacters, string $suffix = '' ) : string
$string string The input string
$maximumCharacters integer Number of characters where cropping should happen
$suffix string Suffix to be appended if cropping was necessary
return string The cropped string

cropAtSentence() public method

Crop a string to maximumCharacters length, taking sentences into account, optionally appending suffix if cropping was necessary.
public cropAtSentence ( string $string, integer $maximumCharacters, string $suffix = '' ) : string
$string string The input string
$maximumCharacters integer Number of characters where cropping should happen
$suffix string Suffix to be appended if cropping was necessary
return string The cropped string

cropAtWord() public method

Crop a string to maximumCharacters length, taking words into account, optionally appending suffix if cropping was necessary.
public cropAtWord ( string $string, integer $maximumCharacters, string $suffix = '' ) : string
$string string The input string
$maximumCharacters integer Number of characters where cropping should happen
$suffix string Suffix to be appended if cropping was necessary
return string The cropped string

endsWith() public method

Example:: String.endsWith('Hello, World!', 'World!') == true
public endsWith ( string $string, string $search, integer $position = null ) : boolean
$string string The string
$search string A string to search
$position integer Optional position for limiting the string
return boolean TRUE if the string ends with the given search

firstLetterToLowerCase() public method

Example:: String.firstLetterToLowerCase('CamelCase') == 'camelCase'
public firstLetterToLowerCase ( string $string ) : string
$string string The input string
return string The string with the first letter in lowercase

firstLetterToUpperCase() public method

Example:: String.firstLetterToUpperCase('hello world') == 'Hello world'
public firstLetterToUpperCase ( string $string ) : string
$string string The input string
return string The string with the first letter in uppercase

htmlSpecialChars() public method

Convert special characters to HTML entities
public htmlSpecialChars ( string $string, boolean $preserveEntities = false ) : string
$string string The string to convert
$preserveEntities boolean ``true`` if entities should not be double encoded
return string The converted string

indexOf() public method

Example:: String.indexOf("Blue Whale", "Blue") == 0
public indexOf ( string $string, string $search, integer $fromIndex = null ) : integer
$string string The input string
$search string The substring to search for
$fromIndex integer The index where the search should start, defaults to the beginning
return integer The index of the substring (>= 0) or -1 if the substring was not found

isBlank() public method

Examples:: String.isBlank('') == true String.isBlank(' ') == true
public isBlank ( string $string ) : boolean
$string string The string to test
return boolean ``true`` if the given string is blank

lastIndexOf() public method

Example:: String.lastIndexOf("Developers Developers Developers!", "Developers") == 22
public lastIndexOf ( string $string, string $search, integer $toIndex = null ) : integer
$string string The input string
$search string The substring to search for
$toIndex integer The position where the backwards search should start, defaults to the end
return integer The last index of the substring (>=0) or -1 if the substring was not found

length() public method

Get the length of a string
public length ( string $string ) : integer
$string string The input string
return integer Length of the string

md5() public method

Calculate the MD5 checksum of the given string
public md5 ( string $string ) : string
$string string The string to hash
return string The MD5 hash of ``string``

pregMatch() public method

Example:: String.pregMatch("For more information, see Chapter 3.4.5.1", "/(chapter \d+(\.\d)*)/i") == ['Chapter 3.4.5.1', 'Chapter 3.4.5.1', '.1']
public pregMatch ( string $string, string $pattern ) : array
$string string The input string
$pattern string A PREG pattern
return array The matches as array or NULL if not matched

pregReplace() public method

Examples:: String.pregReplace("Some.String with sp:cial characters", "/[[:^alnum:]]/", "-") == "Some-String-with-sp-cial-characters" String.pregReplace("2016-08-31", "/([0-9]+)-([0-9]+)-([0-9]+)/", "$3.$2.$1") == "31.08.2016"
public pregReplace ( string $string, string $pattern, string $replace ) : string
$string string The input string
$pattern string A PREG pattern
$replace string A replacement string, can contain references to capture groups with "\\n" or "$n"
return string The string with all occurrences replaced

pregSplit() public method

Examples:: String.pregSplit("foo bar baz", "/\s+/") == ['foo', 'bar', 'baz'] String.pregSplit("first second third", "/\s+/", 2) == ['first', 'second third']
public pregSplit ( string $string, string $pattern, integer $limit = null ) : array
$string string The input string
$pattern string A PREG pattern
$limit integer The maximum amount of items to return, in contrast to split() this will return all remaining characters in the last item (see example)
return array An array of the splitted parts, excluding the matched pattern

rawUrlDecode() public method

Decode the string from URLs according to RFC 3986
public rawUrlDecode ( string $string ) : string
$string string The string to decode
return string The decoded string

rawUrlEncode() public method

Encode the string for URLs according to RFC 3986
public rawUrlEncode ( string $string ) : string
$string string The string to encode
return string The encoded string

replace() public method

Example:: String.replace("canal", "ana", "oo") == "cool" Note: this method does not perform regular expression matching, @see pregReplace().
public replace ( string $string, string $search, string $replace ) : string
$string string The input string
$search string A search string
$replace string A replacement string
return string The string with all occurrences replaced

split() public method

Example:: String.split("My hovercraft is full of eels", " ") == ['My', 'hovercraft', 'is', 'full', 'of', 'eels'] String.split("Foo", "", 2) == ['F', 'o'] Node: This implementation follows JavaScript semantics without support of regular expressions.
public split ( string $string, string $separator = null, integer $limit = null ) : array
$string string The string to split
$separator string The separator where the string should be splitted
$limit integer The maximum amount of items to split (exceeding items will be discarded)
return array An array of the splitted parts, excluding the separators

startsWith() public method

Examples:: String.startsWith('Hello world!', 'Hello') == true String.startsWith('My hovercraft is full of...', 'Hello') == false String.startsWith('My hovercraft is full of...', 'hovercraft', 3) == true
public startsWith ( string $string, string $search, integer $position = null ) : boolean
$string string The input string
$search string The string to search for
$position integer The position to test (defaults to the beginning of the string)
return boolean

stripTags() public method

Example:: String.stripTags('Some link') == 'Some link' This is a wrapper for the strip_tags() PHP function.
public stripTags ( string $string, string $allowableTags = null ) : string
$string string The string to strip
$allowableTags string Specify tags which should not be stripped
return string The string with tags stripped

substr() public method

This implementation follows the JavaScript specification for "substr". Examples:: String.substr('Hello, World!', 7, 5) == 'World' String.substr('Hello, World!', 7) == 'World!' String.substr('Hello, World!', -6) == 'World!'
public substr ( string $string, integer $start, integer $length = null ) : string
$string string A string
$start integer Start offset
$length integer Maximum length of the substring that is returned
return string The substring

substring() public method

This implementation follows the JavaScript specification for "substring". Examples:: String.substring('Hello, World!', 7, 12) == 'World' String.substring('Hello, World!', 7) == 'World!'
public substring ( string $string, integer $start, integer $end = null ) : string
$string string
$start integer Start index
$end integer End index
return string The substring

toBoolean() public method

A value is true, if it is either the string "TRUE" or "true" or the number 1.
public toBoolean ( string $string ) : boolean
$string string The string to convert
return boolean The boolean value of the string (``true`` or ``false``)

toFloat() public method

Convert a string to float
public toFloat ( string $string ) : float
$string string The string to convert
return float The float value of the string

toInteger() public method

Convert a string to integer
public toInteger ( string $string ) : integer
$string string The string to convert
return integer The converted string

toLowerCase() public method

Lowercase a string
public toLowerCase ( string $string ) : string
$string string The input string
return string The string in lowercase

toString() public method

Convert the given value to a string
public toString ( mixed $value ) : string
$value mixed The value to convert (must be convertible to string)
return string The string value

toUpperCase() public method

Uppercase a string
public toUpperCase ( string $string ) : string
$string string The input string
return string The string in uppercase

trim() public method

Trim whitespace at the beginning and end of a string
public trim ( string $string, string $charlist = null ) : string
$string string The string to trim
$charlist string List of characters that should be trimmed, defaults to whitespace
return string The trimmed string