boomdraw / laravel-str
Extends \Illuminate\Support\Str with additional string helpers
Installs: 1 858
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.2
- illuminate/support: 5.5.*|5.6.*|5.7.*|5.8.*|^6.0
Requires (Dev)
- orchestra/testbench: 3.5.*|3.6.*|3.7.*|3.8.*|^4.0
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
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.