PHP code example of sumaiazaman / laravel-stringable-extras

1. Go to this page and download the library: Download sumaiazaman/laravel-stringable-extras library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sumaiazaman / laravel-stringable-extras example snippets


// Callback fires — string doesn't contain 'xxx'
$result = str('hello world')
    ->whenDoesntContain('xxx', fn ($s) => $s->upper());
// 'HELLO WORLD'

// Callback is skipped — string contains 'world'
$result = str('hello world')
    ->whenDoesntContain('world', fn ($s) => $s->upper());
// 'hello world'

// With a default callback
$result = str('hello world')
    ->whenDoesntContain(
        'world',
        fn ($s) => $s->upper(),
        fn ($s) => $s->title(),
    );
// 'Hello World'

// Array of needles — callback fires only if none are present
$result = str('hello world')
    ->whenDoesntContain(['foo', 'bar'], fn ($s) => $s->upper());
// 'HELLO WORLD'

// Callback fires — 'xxx' is not in the string
$result = str('hello world')
    ->whenDoesntContainAll(['hello', 'xxx'], fn ($s) => $s->upper());
// 'HELLO WORLD'

// Callback is skipped — both needles are present
$result = str('hello world')
    ->whenDoesntContainAll(['hello', 'world'], fn ($s) => $s->upper());
// 'hello world'