Overview

Namespaces

  • Liberty
  • None

Classes

  • BigInteger
  • Block
  • Blockchain
  • Collection
  • CollectionFileList
  • File
  • Folder
  • INI
  • LECDSA
  • Onecrypt
  • SSV
  • Text
  • Transaction
  • Wallet
  • WebPeer
  • Overview
  • Namespace
  • Class

Class Text

The Text class provide functions to texts and phases.

Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)

Copyright (c) Liberty Group cryptolibertygroup@gmail.com

Namespace: Liberty
Package: Liberty
Category: Cryptocurrency
License: MIT License.
Author: Liberty Group cryptolibertygroup@gmail.com
Version: 1.0.0
Since: 2017-05-14
Located at Liberty/Text.php
Methods summary
public boolean
# __construct( string $string = "" )

Create a Text object

Create a Text object

Parameters

$string
The text or string to process

Returns

boolean
true or false
public
# setText( $string )
public
# getText( )
public string
# datetimeToText( string $lang = "english" )

Create a Text from datetime format

Create a Text from datetime format

Parameters

$lang
The Language to be returned in english talk. (Ex: spanish).

Returns

string
String with datetime in text.
public string
# monthNumToText( string $lang = "english" )

Create a Text from month number

Create a Text from month number

Parameters

$lang
String with month number (Ex: 02).

Returns

string
The language returned in english talk. (Ex: spanish).
public string
# cutShort( integer|string $chars )

Limit a phrase at $chars long.

Limit a phrase at $chars long.

Parameters

$chars
Long of the phrase.

Returns

string
The phrase cut shorted.
public static string
# uuid( )

Generate a random UUID version 4

Generate a random UUID version 4

Warning: This method should not be used as a random seed for any cryptographic operations. Instead you should use the openssl or mcrypt extensions.

Returns

string
RFC 4122 UUID

Copyright

Matt Farina MIT License https://github.com/lootils/uuid/blob/master/LICENSE

See

http://www.ietf.org/rfc/rfc4122.txt
public static array|string
# 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.

Tokenizes a string using $separator, ignoring any instance of $separator that appears between $leftBound and $rightBound.

Parameters

$data
The data to tokenize.
$separator
The token to split the data on.
$leftBound
The left boundary to ignore separators in.
$rightBound
The right boundary to ignore separators in.

Returns

array|string
Array of tokens in $data or original input if empty.
public static string
# insert( string $str, array $data, array $options = [] )

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:

Text::insert(':name is :age years old.', ['name' => 'Bob', 'age' => '65']);

Returns: Bob is 65 years old.

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:

Text::insert(':name is :age years old.', ['name' => 'Bob', 'age' => '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 Text::cleanInsert

Parameters

$str
A string containing variable placeholders
$data

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

$options
An array of options, see description above

Returns

string
public static string
# cleanInsert( string $str, array $options )

Cleans up a Text::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 Text::insert().

Cleans up a Text::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 Text::insert().

Parameters

$str
String to clean.
$options
Options list.

Returns

string

See

\Cake\Utility\Text::insert()
public static string
# wrap( string $text, array|integer $options = [] )

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

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 String to indent with. Defaults to null.
  • indentAt 0 based index to start indenting at. Defaults to 0.

Parameters

$text
The text to format.
$options
Array of options to use, or an integer to wrap the text to.

Returns

string
Formatted text.
public static string
# wrapBlock( string $text, array|integer $options = [] )

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

Wraps a complete block of 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 String to indent with. Defaults to null.
  • indentAt 0 based index to start indenting at. Defaults to 0.

Parameters

$text
The text to format.
$options
Array of options to use, or an integer to wrap the text to.

Returns

string
Formatted text.
public static string
# wordWrap( string $text, integer $width = 72, string $break = "\n", boolean $cut = false )

Unicode and newline aware version of wordwrap.

Unicode and newline aware version of wordwrap.

Parameters

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

Returns

string
Formatted text.
protected static string
# _wordWrap( string $text, integer $width = 72, string $break = "\n", boolean $cut = false )

Unicode aware version of wordwrap as helper method.

Unicode aware version of wordwrap as helper method.

Parameters

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

Returns

string
Formatted text.
public static string
# highlight( string $text, string|array $phrase, array $options = [] )

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.

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'
  • limit A limit, optional, defaults to -1 (none)

Parameters

$text
Text to search the phrase in.
$phrase
The phrase or phrases that will be searched.
$options
An array of HTML attributes and options.

Returns

string
The highlighted text

Link

http://book.cakephp.org/3.0/en/core-libraries/string.html#highlighting-substrings
public static string
# stripLinks( string $text )

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

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

Warning This method is not an robust solution in preventing XSS or malicious HTML.

Deprecated

3.2.12 This method will be removed in 4.0.0

Parameters

$text
Text

Returns

string
The text without links
public static string
# tail( string $text, integer $length = 100, array $options = [] )

Truncates text starting from the end.

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

$text
String to truncate.
$length
Length of returned string, including ellipsis.
$options
An array of options.

Returns

string
Trimmed string.
public static string
# truncate( string $text, integer $length = 100, array $options = [] )

Truncates text.

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
  • exact If false, $text will not be cut mid-word
  • html If true, HTML tags would be handled correctly
  • trimWidth If true, $text will be truncated with the width

Parameters

$text
String to truncate.
$length
Length of returned string, including ellipsis.
$options
An array of HTML attributes and options.

Returns

string
Trimmed string.

Link

http://book.cakephp.org/3.0/en/core-libraries/string.html#truncating-text
public static string
# truncateByWidth( string $text, integer $length = 100, array $options = [] )

Truncate text with specified width.

Truncate text with specified width.

Parameters

$text
String to truncate.
$length
Length of returned string, including ellipsis.
$options
An array of HTML attributes and options.

Returns

string
Trimmed string.

See

\Cake\Utility\Text::truncate()
protected static integer
# _strlen( string $text, array $options )

Get string length.

Get string length.

Options:

  • html If true, HTML entities will be handled as decoded characters.
  • trimWidth If true, the width will return.

Parameters

$text
The string being checked for length
$options
An array of options.

Returns

integer
protected static string
# _substr( string $text, integer $start, integer $length, array $options )

Return part of a string.

Return part of a string.

Options:

  • html If true, HTML entities will be handled as decoded characters.
  • trimWidth If true, will be truncated with specified width.

Parameters

$text
The input string.
$start
The position to begin extracting.
$length
The desired length.
$options
An array of options.

Returns

string
protected static string
# _removeLastWord( string $text )

Removes the last word from the input text.

Removes the last word from the input text.

Parameters

$text
The input text

Returns

string
public static string
# 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.

Extracts an excerpt from the text surrounding the phrase with a number of characters on each side determined by radius.

Parameters

$text
String to search the phrase in
$phrase
Phrase that will be searched for
$radius
The amount of characters that will be returned on each side of the founded phrase
$ellipsis
Ending that will be appended

Returns

string
Modified string

Link

http://book.cakephp.org/3.0/en/core-libraries/string.html#extracting-an-excerpt
public static string
# toList( array $list, string|null $and = null, string $separator = ', ' )

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

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

Parameters

$list
The list to be joined.
$and
The word used to join the last and second last items together with. Defaults to 'and'.
$separator
The separator used to join all the other items together. Defaults to ', '.

Returns

string
The glued together string.

Link

http://book.cakephp.org/3.0/en/core-libraries/string.html#converting-an-array-to-sentence-form
public static boolean
# isMultibyte( string $string )

Check if the string contain multibyte characters

Check if the string contain multibyte characters

Parameters

$string
value to test

Returns

boolean
public static array
# utf8( string $string )

Converts a multibyte character string to the decimal value of the character

Converts a multibyte character string to the decimal value of the character

Parameters

$string
String to convert.

Returns

array
public static string
# ascii( array $array )

Converts the decimal value of a multibyte character string to a string

Converts the decimal value of a multibyte character string to a string

Parameters

$array
Array

Returns

string
public static mixed
# parseFileSize( string $size, mixed $default = false )

Converts filesize from human readable string to bytes

Converts filesize from human readable string to bytes

Parameters

$size
Size in human readable string like '5MB', '5M', '500B', '50kb' etc.
$default
Value to be returned when invalid size was used, for example 'Unknown type'

Returns

mixed
Number of bytes as integer on success, $default on failure if not false

Throws

InvalidArgumentException
On invalid Unit type.

Link

http://book.cakephp.org/3.0/en/core-libraries/helpers/text.html
public static string
# getTransliteratorId( )

Get default transliterator identifier string.

Get default transliterator identifier string.

Returns

string
Transliterator identifier.
public static
# setTransliteratorId( string $transliteratorId )

Set default transliterator identifier string.

Set default transliterator identifier string.

Parameters

$transliteratorId
Transliterator identifier.
public static string
# transliterate( string $string, string|null $transliteratorId = null )

Transliterate string.

Transliterate string.

Parameters

$string
String to transliterate.
$transliteratorId

Transliterator identifier. If null Text::$_defaultTransliteratorId will be used.

Returns

string

See

http://php.net/manual/en/transliterator.transliterate.php
public static string
# slug( string $string, array $options = [] )

Returns a string with all spaces converted to dashes (by default), characters transliterated to ASCII characters, and non word characters removed.

Returns a string with all spaces converted to dashes (by default), characters transliterated to ASCII characters, and non word characters removed.

Options:

  • replacement: Replacement string. Default '-'.
  • transliteratorId: A valid tranliterator id string. If default null Text::$_defaultTransliteratorId to be used. If false no transliteration will be done, only non words will be removed.
  • preserve: Specific non-word character to preserve. Default null. For e.g. this option can be set to '.' to generate clean file names.

Parameters

$string
the string you want to slug
$options

If string it will be use as replacement character or an array of options.

Returns

string
Properties summary
protected string $text

The text or string to process.

The text or string to process.

#
API documentation generated by ApiGen