On this page
Class TextHelper
Text helper library.
Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
- AppHelper
TextHelper
Link: https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html
See:
String
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/TextHelper.php
Properties summary
-
$_engine
protectedstdClass
-
$_placeholders
protectedarray
An array of md5sums and their contents. Used when inserting links into text.
-
$helpers
publicarray
Magic properties summary
-
$Html
public
Method Summary
-
__call() publicCall methods from CakeText utility class
-
__construct() publicConstructor
-
_insertPlaceHolder() protected
Saves the placeholder for a string, for later use. This gets around double escaping content in URL's.
-
_linkEmails() protectedLinks email addresses
-
_linkUrls() protectedReplace placeholders with links.
-
autoLink() publicConvert all links and email addresses to HTML links.
-
autoLinkEmails() publicAdds email links (<a href="mailto:....) to a given text.
-
autoLinkUrls() public
Adds links (<a href=....) to a given text, by finding text that begins with strings like http:// and ftp://.
-
autoParagraph() public
Formats paragraphs around given text for all line breaks
added for single line return<
p> added for double line return
-
excerpt() public
Extracts an excerpt from the text surrounding the phrase with a number of characters on each side determined by radius.
-
highlight() public
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.
-
stripLinks() publicStrips given text of all links (<a href=....)
-
tail() publicTruncates text starting from the end.
-
toList() publicCreates a comma separated list where the last two items are joined with 'and', forming natural language.
-
truncate() publicTruncates text.
Method Detail
__call()source public
__call( string $method , array $params )
Call methods from CakeText utility class
Parameters
-
string
$method
- Method to call.
-
array
$params
- Parameters to pass to method.
Returns
mixedWhatever is returned by called method, or false on failure
__construct()source public
__construct( View $View , array $settings array() )
Constructor
Settings:
engine
Class name to use to replace CakeText functionality. The class needs to be placed in theUtility
directory.
Parameters
View
$View
- the view object the helper is attached to.
-
array
$settings
optional array() - Settings array Settings array
Throws
CakeException
when the engine class could not be found.
_insertPlaceHolder()source protected
_insertPlaceHolder( array $matches )
Saves the placeholder for a string, for later use. This gets around double escaping content in URL's.
Parameters
-
array
$matches
- An array of regexp matches.
Returns
stringReplaced values.
_linkEmails()source protected
_linkEmails( string $text , array $options )
Links email addresses
Parameters
-
string
$text
- The text to operate on
-
array
$options
- An array of options to use for the HTML.
Returns
stringSee
TextHelper::autoLinkEmails()_linkUrls()source protected
_linkUrls( string $text , array $htmlOptions )
Replace placeholders with links.
Parameters
-
string
$text
- The text to operate on.
-
array
$htmlOptions
- The options for the generated links.
Returns
stringThe text with links inserted.
autoLink()source public
autoLink( string $text , array $options array() )
Convert all links and email addresses to HTML links.
Options
escape
Control HTML escaping of input. Defaults to true.
Parameters
-
string
$text
- Text
-
array
$options
optional array() - Array of HTML options, and options listed above.
Returns
stringThe text with links
Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoLinkautoLinkEmails()source public
autoLinkEmails( string $text , array $options array() )
Adds email links (<a href="mailto:....) to a given text.
Options
escape
Control HTML escaping of input. Defaults to true.
Parameters
-
string
$text
- Text
-
array
$options
optional array() - Array of HTML options, and options listed above.
Returns
stringThe text with links
Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoLinkEmailsautoLinkUrls()source public
autoLinkUrls( string $text , array $options array() )
Adds links (<a href=....) to a given text, by finding text that begins with strings like http:// and ftp://.
Options
escape
Control HTML escaping of input. Defaults to true.
Parameters
-
string
$text
- Text
-
array
$options
optional array() - Array of HTML options, and options listed above.
Returns
stringThe text with links
Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoLinkUrlsautoParagraph()source public
autoParagraph( string $text )
Formats paragraphs around given text for all line breaks
added for single line return
<
p> added for double line return
Parameters
-
string
$text
- Text
Returns
stringThe text with proper
<
p> and
tags
Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoParagraphexcerpt()source public
excerpt( string $text , string $phrase , integer $radius 100 , string $ending '...' )
Extracts an excerpt from the text surrounding the phrase with a number of characters on each side determined by radius.
Parameters
-
string
$text
- String to search the phrase in
-
string
$phrase
- Phrase that will be searched for
-
integer
$radius
optional 100 - The amount of characters that will be returned on each side of the founded phrase
-
string
$ending
optional '...' - Ending that will be appended
Returns
stringModified string
See
CakeText::excerpt()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::excerpthighlight()source public
highlight( string $text , string $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.
Parameters
-
string
$text
- Text to search the phrase in
-
string
$phrase
- The phrase that will be searched
-
array
$options
optional array() - An array of html attributes and options.
Returns
stringThe highlighted text
See
CakeText::highlight()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::highlightstripLinks()source public
stripLinks( string $text )
Strips given text of all links (<a href=....)
Parameters
-
string
$text
- Text
Returns
stringThe text without links
See
CakeText::stripLinks()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::stripLinkstail()source public
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.
Options:
ellipsis
Will be used as Beginning and prepended to the trimmed stringexact
If false, $text will not be cut mid-word
Parameters
-
string
$text
- String to truncate.
-
integer
$length
optional 100 - Length of returned string, including ellipsis.
-
array
$options
optional array() - An array of html attributes and options.
Returns
stringTrimmed string.
See
CakeText::tail()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::tailtoList()source public
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.
Parameters
-
array
$list
- The list to be joined.
-
string
$and
optional null - The word used to join the last and second last items together with. Defaults to 'and'.
-
string
$separator
optional ', ' - The separator used to join all the other items together. Defaults to ', '.
Returns
stringThe glued together string.
See
CakeText::toList()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::toListtruncate()source public
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.
Options:
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
Parameters
-
string
$text
- String to truncate.
-
integer
$length
optional 100 - Length of returned string, including ellipsis.
-
array
$options
optional array() - An array of html attributes and options.
Returns
stringTrimmed string.
See
CakeText::truncate()Link
https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncateProperties detail
$_placeholderssource
protected array
An array of md5sums and their contents. Used when inserting links into text.
array()
Magic properties detail
$Htmlsource
public HtmlHelper
© 2005–2017 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.10/class-TextHelper.html