class Text (View source)

Text manipulation utility class

Constants

WORD_CASELESS

CODE_CASE_SEPARATOR

CODE_CASE_UPPER

Non-initial word letter case option

Expected value is a boolean. The default value is FALSE.

CODE_CASE_CAPITALIZE

Initial word letter case option

CODE_CASE_CAPITALIZE_FIRST_INITIAL

Capitalize first letter of the first word

CODE_CASE_CAPITALIZE_FIRST

CODE_CASE_CAPITALIZE_FOLLOWING_INITIALS

Capitalize first letter of other words

CODE_CASE_CAPITALIZE_OTHER

CODE_CASE_CAPITALIZE_INITIALS

Capitalize first letter of all words

CODE_CASE_CAPITALIZE_ALL

CODE_CASE_CAPITALIZE_WORDS

CODE_CASE_PRESERVE_CAPITAL_WORDS

CODE_CASE_WORD_OPTIONS

Methods

static boolean
isFloat(string $text)

Indicates if the given text represents a floating point number

static boolean
isInteger(string $text)

Indicates if the given text represents an integer

static array|false
firstOf($haystack, $needles = array(), $firstOnly = false)

No description

static string|Hexadecimal
toHexadecimalString(integer|string $value, boolean $upperCase = false)

No description

static string
firstLetterCase(string $text, boolean $upper = true)

Set the first letter case

static 
explodeCodeWords($text, $options = 0)

No description

static string
toCamelCase(string $text, $capitalizationOptions = 0)

Transform text to follow theCamelCase style

static string
toHumanCase(string $text, $capitalizationOptions = 0)

Transform text to "Something a normal human is happy to read"

static string
toKebabCase(string $text)

Transform text to follow the-kebab-case style

static string
toMacroCase(string $text)

Transform text to follow the MACRO_CASE style

static string
toPascalCase(string $text, $capitalizationOptions = 0)

Transform text to follow ThePascalCase style

static string
toSnakeCase($text)

Transform text to follow the_snake_case style

static string
toTitleCase(string $text, $capitalizationOptions = 0)

Transform to to "A Ttile Case"

static 
toTrainCase($text, $capitalizationOptions = 0)

No description

static string
toCodeCase(string $text, array $options)

Transform text to a user defined code style

static 
applyWordCodeCase($word, $capitalizeInitial = false, $keepCapitalWord = false)

No description

Details

static boolean isFloat(string $text)

Indicates if the given text represents a floating point number

Parameters

string $text Input text

Return Value

boolean TRUE if $text represents a floating point number

static boolean isInteger(string $text)

Indicates if the given text represents an integer

Parameters

string $text Input text

Return Value

boolean TRUE if $text represents an integer

static array|false firstOf($haystack, $needles = array(), $firstOnly = false)

Parameters

$haystack
$needles
$firstOnly

Return Value

array|false Position -> needle array or FALSE if none of the $needles can be found in $haystack

static string|Hexadecimal toHexadecimalString(integer|string $value, boolean $upperCase = false)

Parameters

integer|string $value Value to convert
boolean $upperCase Indicates if hexadecimal digit letters should be written uper case or not.

Return Value

string|Hexadecimal representation of the input value. The output string length is always a multiple of 2.

Exceptions

InvalidArgumentException

static string firstLetterCase(string $text, boolean $upper = true)

Set the first letter case

Parameters

string $text Text Input text
boolean $upper Indicate if the first letter must be upper case

Return Value

string

static explodeCodeWords($text, $options = 0)

Parameters

$text
$options

static string toCamelCase(string $text, $capitalizationOptions = 0)

Transform text to follow theCamelCase style

Parameters

string $text Text to transform
$capitalizationOptions Additional apitalization options.

Return Value

string Transformed text

static string toHumanCase(string $text, $capitalizationOptions = 0)

Transform text to "Something a normal human is happy to read"

Parameters

string $text Text to transform
$capitalizationOptions Additional apitalization options.

Return Value

string Transformed text

static string toKebabCase(string $text)

Transform text to follow the-kebab-case style

Parameters

string $text ext to transform

Return Value

string Transformed text

static string toMacroCase(string $text)

Transform text to follow the MACRO_CASE style

Parameters

string $text Text to transform

Return Value

string Transformed text

static string toPascalCase(string $text, $capitalizationOptions = 0)

Transform text to follow ThePascalCase style

Parameters

string $text Text to transform
$capitalizationOptions Additional apitalization options.

Return Value

string Transformed text

static string toSnakeCase($text)

Transform text to follow the_snake_case style

Parameters

$text

Return Value

string Transformed text

static string toTitleCase(string $text, $capitalizationOptions = 0)

Transform to to "A Ttile Case"

Parameters

string $text Text to transform
$capitalizationOptions Additional apitalization options.

Return Value

string Transformed text

static toTrainCase($text, $capitalizationOptions = 0)

Parameters

$text
$capitalizationOptions

static string toCodeCase(string $text, array $options)

Transform text to a user defined code style

Parameters

string $text Text to transform
array $options Style options

Return Value

string Transformed text

static protected applyWordCodeCase($word, $capitalizeInitial = false, $keepCapitalWord = false)

Parameters

$word
$capitalizeInitial
$keepCapitalWord