PHP code example of mucts / string

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

    

mucts / string example snippets


use MuCTS\String\Str;

$converted = Str::camel('foo_bar');
// fooBar

use MuCTS\String\Str;

$result = Str::endsWith('This is my name', 'name');
// true

use MuCTS\String\Str;

$converted = Str::kebab('fooBar');
// foo-bar

use MuCTS\String\Str;

$converted = Str::snake('fooBar');
// foo_bar

use MuCTS\String\Str;

$result = Str::startsWith('This is my name', 'This');
// true

use MuCTS\String\Str;

$slice = Str::after('This is my name', 'This is');
// ' my name'

use MuCTS\String\Str;

$slice = Str::before('This is my name', 'my name');
// 'This is '

use MuCTS\String\Str;

$contains = Str::contains('This is my name', 'my');

// true

use MuCTS\String\Str;

$adjusted = Str::finish('this/string', '/');
// this/string/
$adjusted = Str::finish('this/string/', '/');
// this/string/

use MuCTS\String\Str;
$matches = Str::is('foo*', 'foobar');
// true
$matches = Str::is('baz*', 'foobar');
// false

use MuCTS\String\Str;
$truncated = Str::limit('The quick brown fox jumps over the lazy dog', 20);
// The quick brown fox...

use MuCTS\String\Str;
$truncated = Str::limit('The quick brown fox jumps over the lazy dog', 20, ' (...)');
// The quick brown fox (...)

use MuCTS\String\Str;
return (string) Str::orderedUuid();

use MuCTS\String\Str;
$plural = Str::plural('car');
// cars
$plural = Str::plural('child');
// children

use MuCTS\String\Str;
$plural = Str::plural('child', 2);
// children
$plural = Str::plural('child', 1);
// child

use MuCTS\String\Str;
$random = Str::random(40);

use MuCTS\String\Str;
$string = 'The event will take place between ? and ?';
$replaced = Str::replaceArray('?', ['8:30', '9:00'], $string);
// The event will take place between 8:30 and 9:00

use MuCTS\String\Str;

$replaced = Str::replaceFirst('the', 'a', 'the quick brown fox jumps over the lazy dog');
// a quick brown fox jumps over the lazy dog

use MuCTS\String\Str;

$replaced = Str::replaceLast('the', 'a', 'the quick brown fox jumps over the lazy dog');
// the quick brown fox jumps over a lazy dog

use MuCTS\String\Str;

$singular = Str::singular('cars');
// car
$singular = Str::singular('children');
// child

use MuCTS\String\Str;

$slug = Str::slug('Laravel 5 Framework', '-');
// laravel-5-framework

use MuCTS\String\Str;

$adjusted = Str::start('this/string', '/');
// /this/string

$adjusted = Str::start('/this/string', '/');
// /this/string

use MuCTS\String\Str;

$converted = Str::studly('foo_bar');
// FooBar

use MuCTS\String\Str;

$converted = Str::title('a nice title uses the correct case');
// A Nice Title Uses The Correct Case

use MuCTS\String\Str;

return (string) Str::uuid();