Library
Class

Library\Helper\Text

class Text

Text helper

As for all helpers, all methods are statics.

For convenience, the best practice is to use:

use Library\Helper\Text as TextHelper;

Methods

static string cut(string $string = '', int $length = 120, string $end_str = ' ...')

Truncate a string at a maximum length, adding it a suffix like '...'

static string wrap($str $str = '', int $line_length = 75, string $separator = PHP_EOL)

static string stripSpecialChars(string $string = '', string $authorized = '')

Strip all special characters in a string

static string slugify(string $string = '')

Get a slugified string

static string getHumanReadable(string $string = '')

Transform a string to a human readable one

static string toCamelCase(string $name = '', string $replace = '_', bool $capitalize_first_char = true)

Transform a name in CamelCase

static string fromCamelCase(string $name = '', string $replace = '_', bool $lowerize_first_char = true)

Transform a name from CamelCase to other

Details

at line 48
static public string cut(string $string = '', int $length = 120, string $end_str = ' ...')

Truncate a string at a maximum length, adding it a suffix like '...'

Parameters

string $string The string to cut
int $length The maximum length to keep (120 by default)
string $end_str The suffix to add if the string was cut (... by default)

Return Value

string

at line 74
static public string wrap($str $str = '', int $line_length = 75, string $separator = PHP_EOL)

Parameters

$str $str
int $line_length
string $separator

Return Value

string

at line 99
static public string stripSpecialChars(string $string = '', string $authorized = '')

Strip all special characters in a string

This will replace all accentuated letters by their non-accentuated equivalent and delete all other special characters (including space by default).

Parameters

string $string The string to format
string $authorized Some authorized characters

Return Value

string

at line 126
static public string slugify(string $string = '')

Get a slugified string

By Miguel Santirso (http://sourcecookbook.com/en/recipes/8/function-to-slugify-strings-in-php)

Parameters

string $string The string to format

Return Value

string

at line 142
static public string getHumanReadable(string $string = '')

Transform a string to a human readable one

Parameters

string $string The string to transform

Return Value

string The transformed version of $string

at line 155
static public string toCamelCase(string $name = '', string $replace = '_', bool $capitalize_first_char = true)

Transform a name in CamelCase

Parameters

string $name The string to transform
string $replace Replacement character
bool $capitalize_first_char May the first letter be in upper case (default is true)

Return Value

string The CamelCase version of $name

at line 175
static public string fromCamelCase(string $name = '', string $replace = '_', bool $lowerize_first_char = true)

Transform a name from CamelCase to other

Parameters

string $name The string to transform
string $replace Replacement character
bool $lowerize_first_char May the first letter be in lower case (default is true)

Return Value

string The un-CamelCase version of $name