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.9 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.9
      • 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
  • None

Classes

  • CakeNumber
  • CakeText
  • CakeTime
  • ClassRegistry
  • Debugger
  • File
  • Folder
  • Hash
  • Inflector
  • ObjectCollection
  • Sanitize
  • Security
  • Set
  • String
  • Validation
  • Xml

Class String

String handling methods.

CakeText
Extended by String
Package: Cake\Utility
Deprecated: 3.0.0 Deprecated since version 2.7, use CakeText class instead.
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Utility/String.php

Methods inherited from CakeText

_wordWrap() protected static ¶

_wordWrap( string $text , integer $width = 72 , string $break = "\n" , boolean $cut = false )

Helper method for wordWrap().

Parameters
string $text
The text to format.
integer $width optional 72
The width to wrap to. Defaults to 72.
string $break optional "\n"
The line is broken using the optional break parameter. Defaults to '\n'.
boolean $cut optional false
If the cut is set to true, the string is always wrapped at the specified width.
Returns
string
Formatted text.

cleanInsert() public static ¶

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().

Parameters
string $str
CakeText to clean.
array $options
Options list.
Returns
string
See
CakeText::insert()

excerpt() public static ¶

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.

Parameters
string $text
CakeText 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 $ellipsis optional '...'
Ending that will be appended
Returns
string
Modified string
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::excerpt

highlight() public static ¶

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.

Options:

  • format The piece of html with that the phrase will be highlighted
  • html If true, will ignore any HTML tags, ensuring that only the correct text is highlighted
  • regex a custom regex rule that is used to match words, default is '|$tag|iu'
Parameters
string $text
Text to search the phrase in.
string|array $phrase
The phrase or phrases that will be searched.
array $options optional array()
An array of html attributes and options.
Returns
string
The highlighted text
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::highlight

insert() public static ¶

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:

  • before: The character or string in front of the name of the variable placeholder (Defaults to :)
  • after: The character or string after the name of the variable placeholder (Defaults to null)
  • escape: The character or string used to escape the before character / string (Defaults to \)
  • format: A regex to use for matching variable placeholders. Default is: /(?<!\\)\:%s/ (Overwrites before, after, breaks escape / clean)
  • clean: A boolean or array with instructions for CakeText::cleanInsert
Parameters
string $str
A string containing variable placeholders
array $data

A key => val array where each key stands for a placeholder variable name to be replaced with val

array $options optional array()
An array of options, see description above
Returns
string

stripLinks() public static ¶

stripLinks( string $text )

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

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

tail() public static ¶

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
CakeText to truncate.
integer $length optional 100
Length of returned string, including ellipsis.
array $options optional array()
An array of options.
Returns
string
Trimmed string.

toList() public static ¶

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

tokenize() public static ¶

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.

Parameters
string $data
The data to tokenize.
string $separator optional ','
The token to split the data on.
string $leftBound optional '('
The left boundary to ignore separators in.
string $rightBound optional ')'
The right boundary to ignore separators in.
Returns
mixed
Array of tokens in $data or original input if empty.

truncate() public static ¶

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
CakeText 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.
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/text.html#TextHelper::truncate

uuid() public static ¶

uuid( )

Generate a random UUID

Returns
string
RFC 4122 UUID
See
http://www.ietf.org/rfc/rfc4122.txt

wordWrap() public static ¶

wordWrap( string $text , integer $width = 72 , string $break = "\n" , boolean $cut = false )

Unicode aware version of wordwrap.

Parameters
string $text
The text to format.
integer $width optional 72
The width to wrap to. Defaults to 72.
string $break optional "\n"
The line is broken using the optional break parameter. Defaults to '\n'.
boolean $cut optional false
If the cut is set to true, the string is always wrapped at the specified width.
Returns
string
Formatted text.

wrap() public static ¶

wrap( string $text , array|integer $options = array() )

Wraps text to a specific width, can optionally wrap at word breaks.

Options

  • 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.
Parameters
string $text
The text to format.
array|integer $options optional array()
Array of options to use, or an integer to wrap the text to.
Returns
string
Formatted text.
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