String handling methods.
Cleans up a CakeText::insert() formatted string with given $options depending on the 'clean' key in $options. The default method used is text but html is also available. The goal of this function is to replace all whitespace and unneeded markup around placeholders that did not get replaced by CakeText::insert().
Extracts an excerpt from the text surrounding the phrase with a number of characters on each side determined by radius.
Highlights a given phrase in a text. You can specify any expression in highlighter that may include the \1 expression to include the $phrase found.
Replaces variable placeholders inside a $str with any given $data. Each key in the $data array corresponds to a variable placeholder name in $str. Example: CakeText::insert(':name is :age years old.', array('name' => 'Bob', '65'));
Returns: Bob is 65 years old.
Tokenizes a string using $separator, ignoring any instance of $separator that appears between $leftBound and $rightBound.
_wordWrap( string $text , integer $width 72 , string $break "\n" , boolean $cut false )
Helper method for wordWrap().
$text
$width
optional 72 $break
optional "\n" $cut
optional false cleanInsert( string $str , array $options )
Cleans up a CakeText::insert() formatted string with given $options depending on the 'clean' key in $options. The default method used is text but html is also available. The goal of this function is to replace all whitespace and unneeded markup around placeholders that did not get replaced by CakeText::insert().
$str
$options
excerpt( string $text , string $phrase , integer $radius 100 , string $ellipsis '...' )
Extracts an excerpt from the text surrounding the phrase with a number of characters on each side determined by radius.
$text
$phrase
$radius
optional 100 $ellipsis
optional '...' highlight( string $text , string|array $phrase , array $options array() )
Highlights a given phrase in a text. You can specify any expression in highlighter that may include the \1 expression to include the $phrase found.
format
The piece of html with that the phrase will be highlightedhtml
If true, will ignore any HTML tags, ensuring that only the correct text is highlightedregex
a custom regex rule that is used to match words, default is '|$tag|iu'$text
$phrase
$options
optional array() insert( string $str , array $data , array $options array() )
Replaces variable placeholders inside a $str with any given $data. Each key in the $data array corresponds to a variable placeholder name in $str. Example: CakeText::insert(':name is :age years old.', array('name' => 'Bob', '65'));
Returns: Bob is 65 years old.
Available $options are:
:
)\
)/(?<!\\)\:%s/
(Overwrites before, after, breaks escape / clean)$str
$data
A key => val array where each key stands for a placeholder variable name to be replaced with val
$options
optional array() stripLinks( string $text )
Strips given text of all links (<a href=....).
$text
tail( string $text , integer $length 100 , array $options array() )
Truncates text starting from the end.
Cuts a string to the length of $length and replaces the first characters with the ellipsis if the text is longer than length.
ellipsis
Will be used as Beginning and prepended to the trimmed stringexact
If false, $text will not be cut mid-word$text
$length
optional 100 $options
optional array() toList( array $list , string $and null , string $separator ', ' )
Creates a comma separated list where the last two items are joined with 'and', forming natural language.
$list
$and
optional null $separator
optional ', ' tokenize( string $data , string $separator ',' , string $leftBound '(' , string $rightBound ')' )
Tokenizes a string using $separator, ignoring any instance of $separator that appears between $leftBound and $rightBound.
$data
$separator
optional ',' $leftBound
optional '(' $rightBound
optional ')' truncate( string $text , integer $length 100 , array $options array() )
Truncates text.
Cuts a string to the length of $length and replaces the last characters with the ellipsis if the text is longer than length.
ellipsis
Will be used as Ending and appended to the trimmed string (ending
is deprecated)exact
If false, $text will not be cut mid-wordhtml
If true, HTML tags would be handled correctly$text
$length
optional 100 $options
optional array() uuid( )
Generate a random UUID
wordWrap( string $text , integer $width 72 , string $break "\n" , boolean $cut false )
Unicode aware version of wordwrap.
$text
$width
optional 72 $break
optional "\n" $cut
optional false wrap( string $text , array|integer $options array() )
Wraps text to a specific width, can optionally wrap at word breaks.
width
The width to wrap to. Defaults to 72.wordWrap
Only wrap on words breaks (spaces) Defaults to true.indent
CakeText to indent with. Defaults to null.indentAt
0 based index to start indenting at. Defaults to 0.$text
$options
optional array()
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.9/class-CakeText.html