Class TextHelper
Text helper library.
Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...
- AppHelper
 - 
			
TextHelper			
			
			
		 
Link: http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html
See:
StringCopyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/TextHelper.php
Properties summary
- 
			
$_engineprotectedstdClassCakeText utility instance - 
			
$_placeholdersprotectedarrayAn array of md5sums and their contents. Used when inserting links into text.
 - 
			
$helperspublicarrayhelpers 
Magic properties summary
- 
			
$Htmlpublic 
Method Summary
- 
			
__call() public
Call methods from CakeText utility class - 
			
__construct() public
Constructor - 
			
_insertPlaceHolder() protected
Saves the placeholder for a string, for later use. This gets around double escaping content in URL's.
 - 
			
_linkEmails() protected
Links email addresses - 
			
_linkUrls() protected
Replace placeholders with links. - 
			
autoLink() public
Convert all links and email addresses to HTML links. - 
			
autoLinkEmails() public
Adds 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() public
Strips given text of all links (<a href=....) - 
			
tail() public
Truncates text starting from the end. - 
			
toList() public
Creates a comma separated list where the last two items are joined with 'and', forming natural language. - 
			
truncate() public
Truncates text. 
Method Detail
__call() 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
Whatever is returned by called method, or false on failure
__construct() public ¶
__construct( View $View , array $settings = array() )
		
Constructor
Settings:
engineClass name to use to replace CakeText functionality. The class needs to be placed in theUtilitydirectory.
Parameters
- 
						
View$View - the view object the helper is attached to.
 - array $settings optional array()
 - Settings array Settings array
 
Throws
_insertPlaceHolder() 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
Replaced values.
_linkEmails() 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
See
_linkUrls() 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
The text with links inserted.
autoLink() public ¶
autoLink( string $text , array $options = array() )
Convert all links and email addresses to HTML links.
Options
escapeControl HTML escaping of input. Defaults to true.
Parameters
- string $text
 - Text
 - array $options optional array()
 - Array of HTML options, and options listed above.
 
Returns
The text with links
Link
autoLinkEmails() public ¶
autoLinkEmails( string $text , array $options = array() )
Adds email links (<a href="mailto:....) to a given text.
Options
escapeControl HTML escaping of input. Defaults to true.
Parameters
- string $text
 - Text
 - array $options optional array()
 - Array of HTML options, and options listed above.
 
Returns
The text with links
Link
autoLinkUrls() 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
escapeControl HTML escaping of input. Defaults to true.
Parameters
- string $text
 - Text
 - array $options optional array()
 - Array of HTML options, and options listed above.
 
Returns
The text with links
Link
autoParagraph() 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
The text with proper
<
p> and 
 tags
Link
excerpt() 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
Modified string
See
Link
highlight() 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
The highlighted text
See
Link
stripLinks() public ¶
stripLinks( string $text )
Strips given text of all links (<a href=....)
Parameters
- string $text
 - Text
 
Returns
The text without links
See
Link
tail() 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:
ellipsisWill be used as Beginning and prepended to the trimmed stringexactIf 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
Trimmed string.
See
Link
toList() 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
The glued together string.
See
Link
truncate() 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:
ellipsisWill be used as Ending and appended to the trimmed string (endingis deprecated)exactIf false, $text will not be cut mid-wordhtmlIf 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
Trimmed string.
See
Link
Properties detail
$_placeholders ¶
An array of md5sums and their contents. Used when inserting links into text.
array()