Text Component

MIT License

Text Component is a set of methods to help with the manipulation of strings.


composer require flextype-components/text


use Flextype\Component\Text\Text;

Translit function to convert text from one script to another.

echo Text::translitIt('Привет');

Removes any leading and traling slashes from a string

echo Text::trimSlashes('some text here/');

Reduces multiple slashes in a string to single slashes.

echo Text::reduceSlashes('some//text//here');

Removes single and double quotes from a string

echo Text::stripQuotes('some "text" here');

Convert single and double quotes to entities

echo Text::quotesToEntities('some "text" here');

Creates a random string of characters

echo Text::random();

Add's string_1 to a string or increment the ending number to allow string_2, string_3, etc

$str = Text::increment($str);

Cut string

echo Text::cut('Some text here', 5);


echo Text::lowercase('Some text here');


echo Text::uppercase('some text here');

Get length

echo Text::length('Some text here');

Create a lorem ipsum text

echo Text::lorem(2);

Extract the last $num characters from a string.

echo Text::right('Some text here', 4);

Extract the first $num characters from a string.

echo Text::left('Some text here', 4);

Replaces newline with <br> or <br />.

echo Text::nl2br("Some \n text \n here");

Replaces <br> and <br /> with newline.

echo Text::br2nl("Some <br /> text <br /> here");

Converts & to &.

echo Text::ampEncode("M&CMS");

Converts & to &.

echo Text::ampDecode("M&amp;CMS");

Convert plain text to html

echo Text::toHtml('test');

Create safe string. Use to create safe usernames or filenames.

$safe_string = Text::safeString('hello world');

Encrypt string

$encrypt_string = Text::encryptString('password', 'string_salt');




Download on the Github