boomdraw/laravel-str

This package is abandoned and no longer maintained. No replacement package was suggested.

Extends \Illuminate\Support\Str with additional string helpers

v1.1.1 2019-12-10 22:48 UTC

This package is auto-updated.

Last update: 2020-08-11 19:55:33 UTC


README

A package that extends \Illuminate\Support\Str with additional string helpers

Build Status StyleCI Code Coverage Quality Score Latest Version on Packagist Total Downloads PHP Version License

Installation

Via Composer

composer require boomdraw/laravel-str

Laravel

The package will automatically register itself.

Lumen

Register StrServiceProvider

// bootstrap/app.php:
$app->register(Boomdraw\Str\StrServiceProvider::class);

Usage and methods

use Illuminate\Support\Str;

between

The function returns the portion of the string specified by the start and end parameters.

Str::between(string $string, string $start, string $end, bool $strict = true);

The function returns string between $start and $end.

Str::between('foo bar baz', 'foo ', ' baz') === 'bar';

The function returns false if $strict = true and $start or $end is missing in the $string.

Str::between('foo bar baz', 'test ', ' test') === false;
Str::between('foo bar baz', 'foo ', ' test') === false;
Str::between('foo bar baz', 'test ', ' baz') === false;

For the disabled strict mode result will be:

  • source $string if $start and $end are missing in the $string.
Str::between('foo bar baz', 'test ', ' test', false) === 'foo bar baz';
  • source $string before $end if $start is missing in the $string.
Str::between('foo bar baz', 'test ', ' baz', false) === 'foo bar';
  • source $string after $start if $end is missing in the $string.
Str::between('foo bar baz', 'foo ', ' test', false) === 'bar baz';

wbetween

The function returns the portion of the string specified by the start and end parameters wrapped with those parameters.

Str::wbetween(string $string, string $start, string $end, bool $strict = true);

The function returns string between $start and $end wrapped with $start and $end.

Str::wbetween('goo foo bar baz haz', 'foo ', ' baz') === 'foo bar baz';

The function returns false if $strict = true and $start or $end is missing in the $string.

Str::wbetween('goo foo bar baz haz', 'test ', ' test') === false;
Str::wbetween('goo foo bar baz haz', 'foo ', ' test') === false;
Str::wbetween('goo foo bar baz haz', 'test ', ' baz') === false;

For the disabled strict mode result will be:

  • source $string if $start and $end are missing in the $string.
Str::wbetween('goo foo bar baz haz', 'test ', ' test', false) === 'goo foo bar baz haz';
  • source $string without substring after $end if $start is missing in the $string.
Str::wbetween('goo foo bar baz haz', 'test ', ' baz', false) === 'goo foo bar baz';
  • source $string without substring before $start if $end is missing in the $string.
Str::wbetween('goo foo bar baz haz', 'foo ', ' test', false) === 'foo bar baz haz';

utrim

The function calls trim() function with slash (/) and backslash (\) added to charlist.

Str::utrim(string $string): string;
Str::utrim("\hello world \n") === 'hello world';

Testing

You can run the tests with:

composer test

Contributing

Please see CONTRIBUTING for details and a todo list.

Security

If you discover any security-related issues, please email pkgsecurity@boomdraw.com instead of using the issue tracker.

License

MIT