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:
String
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/View/Helper/TextHelper.php
Properties summary
-
$_engine
protectedString utility instance -
$_placeholders
protectedarray
An array of md5sums and their contents. Used when inserting links into text.
-
$helpers
publicarray
helpers
Magic properties summary
-
$Html
public
Method Summary
-
__call() public
Call methods from String 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://.
-
excerpt() public
-
highlight() public
-
stripLinks() public
-
toList() public
-
truncate() public
Method Detail
__construct() public ¶
__construct( View
$View , array $settings = array() )
Constructor
Settings:
engine
Class name to use to replace String 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
_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
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
The text with links
Link
autoLinkEmails() 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
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
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
The text with links
Link
excerpt() public ¶
excerpt( string $text , string $phrase , integer $radius = 100 , string $ending = '...' )
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() )
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 )
Parameters
- string $text
- Text
Returns
The text without links
See
Link
toList() public ¶
toList( array $list , string $and = 'and' , string $separator = ', ' )
Parameters
- array $list
- The list to be joined
- string $and optional 'and'
- 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() )
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()