PHP code example of coyote6 / laravel-str

1. Go to this page and download the library: Download coyote6/laravel-str 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/ */

    

coyote6 / laravel-str example snippets


use Illuminate\Support\Str;

$converted = Str::dot('User - View All');

// user.view.all

Str::dot('Posts - Create Draft');

// posts.create.draft

use Illuminate\Support\Str;

Str::isCamel('aCamelLikeString');

// true

Str::isCamel('A Camel-like String');

// false

use Illuminate\Support\Str;

Str::isDot('user.view.all');

// true

Str::isDot('User - View All');

// false

use Illuminate\Support\Str;

Str::isKebab('a-kebab-like-string');

// true

Str::isKebab('A Kebab-like String');

// false

use Illuminate\Support\Str;

Str::isLower('a lowercased string');

// true

Str::isLower('A Lowercased String');

// false

use Illuminate\Support\Str;

Str::isPascal('APascalOrStudlyLikeString');

// true

Str::isPascal('A Pascal Or Studly-like String');

// false

Str::isPascal('CBOR', true);

// false - normalize would rewrite it to 'Cbor' first

use Illuminate\Support\Str;

Str::isPureKebab('a-kebab-like-string');

// true

Str::isPureKebab('a_kebab_like_string');

// false

Str::isPureKebab('a--kebab--like--string');

// true - repeated dashes are fine by default

Str::isPureKebab('a--kebab--like--string', 1);

// false - exceeds the 1-consecutive-dash limit

use Illuminate\Support\Str;

Str::isPureSnake('a_snakelike_string');

// true

Str::isPureSnake('a-snakelike-string');

// false

Str::isPureSnake('a__snakelike__string');

// true - repeated underscores are fine by default

Str::isPureSnake('a__snakelike__string', 1);

// false - exceeds the 1-consecutive-underscore limit

use Illuminate\Support\Str;

Str::isSlug('a-url-slug');

// true

Str::isSlug('A Url Slug');

// false

Str::isSlug('a_url_slug', '_');

// true

Str::isSlug('café');

// false - 'en' (the default) transliterates é to e, so 'café' no longer matches itself

Str::isSlug('café', '-', null);

// true - transliteration disabled, so the accented letter passes through unchanged

use Illuminate\Support\Str;

Str::isSnake('a_snakelike_string');

// true

Str::isSnake('A Snake-like String');

// false

Str::isSnake('a-snake-case', '-');

// true

use Illuminate\Support\Str;

Str::isStrictKebab('a-kebab-like-string');

// true

Str::isStrictKebab('a--kebab--like--string');

// false

use Illuminate\Support\Str;

Str::isStrictSnake('a_snakelike_string');

// true

Str::isStrictSnake('a__snakelike__string');

// false

use Illuminate\Support\Str;

Str::isStudly('AStudlyLikeString');

// true

Str::isStudly('A Studly-like String');

// false

Str::isStudly('CBOR');

// true - acronyms are left alone by default

Str::isStudly('CBOR', true);

// false - normalize would rewrite it to 'Cbor' first

Str::isStudly('Cbor', true);

// true - already in the normalized shape

use Illuminate\Support\Str;

Str::isTitle('A Title For Your Article');

// true

Str::isTitle('A-Title-for-Your-Article');

// false

use Illuminate\Support\Str;

Str::isUpper('AN UPPERCASED STRING');

// true

Str::isUpper('An uppercased string');

// false

use Illuminate\Support\Str;

Str::pureKebab('my_example_text');

// my-example-text

Str::pureKebab('my_exampleCombined_text');

// my-example-combined-text

Str::pureKebab('A - Kebab');

// a---kebab - each of the 3 separator characters (space, dash, space) converts on its own

Str::kebab('my_example_text'); // for comparison

// my_example_text (Str::kebab() leaves this untouched)

Str::pureKebab('A - Kebab', 2);

// a--kebab

use Illuminate\Support\Str;

Str::pureSnake('my-example-text');

// my_example_text

Str::pureSnake('LARAVELFramework');

// laravel_framework

Str::pureSnake('a - snake');

// a___snake - each of the 3 separator characters (space, dash, space) converts on its own

Str::snake('LARAVELFramework'); // for comparison

// l_a_r_a_v_e_l_framework (Str::snake() splits every capital letter)

Str::pureSnake('a - snake', 2);

// a__snake

use Illuminate\Support\Str;

Str::strictKebab('my_example_text');

// my-example-text

Str::strictKebab('A - Kebab');

// a-kebab

Str::pureKebab('A - Kebab'); // for comparison

// a---kebab (pureKebab() preserves each separator character)

use Illuminate\Support\Str;

Str::strictSnake('my-example-text');

// my_example_text

Str::strictSnake('a - snake');

// a_snake

Str::pureSnake('a - snake'); // for comparison

// a___snake (pureSnake() preserves each separator character)