Skip to content

ErickZH/laravel-string-macros

 
 

Repository files navigation

A set of useful Laravel string macros

Latest Version on Packagist Run Tests Check & fix styling Total Downloads

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Installation

You can install the package via composer:

composer require victoryoalli/laravel-string-macros

Macros

Initials

Gets the initicals of the words you provide. It defaults to 2 initials.

Str::initials('Victor Yoalli Dominguez'); //default to 2 initials
// VY

Str::initials('Victor Yoalli Dominguez',3);
// VYD

Interpolate

Replaces question mark symbol to the words that you provide.

Str::interpolate('Roses are ? Violets are ?','RED','BLUE');
// Roses are RED Violets are BLUE

Str::interpolate('Roses are ? Violets are ?',['RED','BLUE']);
// Roses are RED Violets are BLUE

Str::interpolate('Roses are ? Violets are ?',...['RED','BLUE']);
// Roses are RED Violets are BLUE

readingMinutes

Calculates how many minutes it takes to read the text provided. It accepts HTML too, it will strip tags to make an accurate calculation.

Str::readingMinutes('Roses are RED Violets are BLUE...');
// 1

Str::readingMinutes('Pellentesque purus imperdiet dis duis netus dapibus mattis adipiscing at ultricies, rutrum volutpat quam ex himenaeos consectetur fusce tempus nostra, mollis fermentum ac fringilla donec lobortis potenti eros pharetra...');
// 1

stripTags

Str::stripTags('<strong>Hello</strong> <i>World!</i>');
// Hello World!

wordsCount

Str::wordsCount('Hac non ipsum dolor nisi penatibus maecenas luctus purus rutrum, commodo leo sed ut lacinia gravida primis aliquet eget finibus, consequat sapien platea urna vehicula adipiscing est tortor.');
// 28

Fluent String supported

Example

$str = Str::of('Hac non ? dolor nisi penatibus maecenas luctus purus rutrum, ? leo sed ut lacinia gravida primis aliquet eget finibus, consequat sapien platea urna vehicula adipiscing est tortor.')->interpolate(['RED','BLUE'])->initials(28)->upper();
echo $str;
// HNRDNPMLPRBLSULGPAEFCSPUVAET

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A set of useful Laravel string macros

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%