Class String
String handling methods.
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: string.php
Method Summary
-
cleanInsert() public
Cleans up a String::insert() formated 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 uneeded markup around placeholders that did not get replaced by String::insert().
-
insert() public
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:
String::insert(':name is :age years old.', array('name' => 'Bob', '65'));
Returns: Bob is 65 years old. -
tokenize() public
Tokenizes a string using $separator, ignoring any instance of $separator that appears between $leftBound and $rightBound
-
uuid() public
Generate a random UUID
Method Detail
cleanInsert() public ¶
cleanInsert( string $str , string $options )
Cleans up a String::insert() formated 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 uneeded markup around placeholders that did not get replaced by String::insert().
Parameters
- string $str
- string $options
Returns
See
insert() public ¶
insert( string $str , string $data , string $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: String::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 String::cleanInsert
Parameters
- string $str
- A string containing variable placeholders
- string $data
A key => val array where each key stands for a placeholder variable name to be replaced with val
- string $options optional array()
- An array of options, see description above
Returns
tokenize() public ¶
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
Array of tokens in $data.