CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.5 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.5
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CacheHelper
  • FormHelper
  • HtmlHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • MootoolsEngineHelper
  • NumberHelper
  • PaginatorHelper
  • PrototypeEngineHelper
  • RssHelper
  • SessionHelper
  • TextHelper
  • TimeHelper

Class TextHelper

Text helper library.

Text manipulations: Highlight, excerpt, truncate, strip of links, convert email addresses to mailto: links...

AppHelper
Extended by TextHelper
Package: Cake\View\Helper
Link: http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html
See: String
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/TextHelper.php

Properties summary

  • $_engine protected
    stdClass
    String utility instance
  • $_placeholders protected
    array

    An array of md5sums and their contents. Used when inserting links into text.

  • $helpers public
    array
    helpers

Magic properties summary

  • $Html public
    HtmlHelper

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://.

  • 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 English
  • truncate() public
    Truncates text.

Method Detail

__call() public ¶

__call( string $method , array $params )

Call methods from String utility class

Parameters
string $method
Method to call.
array $params
Parameters to pass to method.
Returns
mixed
Whatever is returned by called method, or false on failure

__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 the Utility 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() 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
string
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
string
See
TextHelper::autoLinkEmails()

_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
string
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
string
The text with links
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoLink

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
string
The text with links
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoLinkEmails

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
string
The text with links
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoLinkUrls

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
string

The text with proper

<

p> and
tags


Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::autoParagraph

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
string
Modified string
See
String::excerpt()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::excerpt

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
string
The highlighted text
See
String::highlight()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::highlight

stripLinks() public ¶

stripLinks( string $text )

Strips given text of all links (<a href=....)

Parameters
string $text
Text
Returns
string
The text without links
See
String::stripLinks()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::stripLinks

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:

  • ellipsis Will be used as Beginning and prepended to the trimmed string
  • exact 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
string
Trimmed string.
See
String::tail()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::tail

toList() public ¶

toList( array $list , string $and = 'and' , string $separator = ', ' )

Creates a comma separated list where the last two items are joined with 'and', forming natural English

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
string
The glued together string.
See
String::toList()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::toList

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:

  • ellipsis Will be used as Ending and appended to the trimmed string (ending is deprecated)
  • exact If false, $text will not be cut mid-word
  • html 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
string
Trimmed string.
See
String::truncate()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate

Properties detail

$_engine ¶

protected stdClass

String utility instance

$_placeholders ¶

protected array

An array of md5sums and their contents. Used when inserting links into text.

array()

$helpers ¶

public array

helpers

array('Html')

Magic properties detail

$Html ¶

public HtmlHelper
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs