PHP code example of artarts36 / str

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

    

artarts36 / str example snippets


use ArtARTs36\Str\Str;

var_dump(Str::make("Водка")->chars());
//array(5) {
//  [0] =>
//  string(2) "В"
//  [1] =>
//  string(2) "о"
//  [2] =>
//  string(2) "д"
//  [3] =>
//  string(2) "к"
//  [4] =>
//  string(2) "а"
//}


use ArtARTs36\Str\Str;

var_dump(Str::make("test")->count()); // 4

use ArtARTs36\Str\Str;

var_dump(Str::make("Test")->toLower()); // test

use ArtARTs36\Str\Str;

$string = 'Hello Hello Hello Artem Hello Artem Hello Artem Artem';
$str = Str::make($string);

var_dump($str->positions('artem', true)); // [18, 30, 42, 48]
var_dump($str->positions('Hello')); // [0, 6, 12, 24, 36]

use ArtARTs36\Str\Str;

var_dump(Str::make('Artem')->reverse()); // metrA

use ArtARTs36\Str\Str;

var_dump(Str::make('Hello')->append('Artem', ' ')); // Hello Artem 

use ArtARTs36\Str\Str;

var_dump(Str::make('Dev')->prepend('Hello', ' ')); // Hello Dev 

use ArtARTs36\Str\Str;

var_dump(Str::make('Dev')->equals('dev')); // false
var_dump(Str::make('Dev')->equals('Dev')); // true

use ArtARTs36\Str\Str;

var_dump(Str::make('Dev')->deleteLastSymbol()); // De

use ArtARTs36\Str\Str;

var_dump(Str::make('Dev')->deleteFirstSymbol()); // ev

use ArtARTs36\Str\Str;

var_dump(Str::make('Test A B')->delete(['Test', 'A'])); // "  B"
var_dump(Str::make('Test A B')->delete(['Test', 'A'], true)); // "B"

use ArtARTs36\Str\Str;

var_dump(Str::make('  TEST ')->trim()); // "TEST"

use ArtARTs36\Str\Str;

foreach (Str::make('test') as $char) {
    var_dump($char);
}
// t
// e
// s
// t

use ArtARTs36\Str\Str;

var_dump(Str::make('TEST 123')->words()); // ['TEST', '123']

use ArtARTs36\Str\Str;

var_dump(Str::make('TEST 123')->isEmpty()); // false
var_dump(Str::make(' ')->isEmpty()); // true

use ArtARTs36\Str\Str;

var_dump(Str::make('AABBBCCC')->usingLetters());
// [A, B, C]

use ArtARTs36\Str\Str;

var_dump(Str::make('AABBBCCC')->getLettersStat()->getDict());
// [A => 2, B => 3, C => 3]

use ArtARTs36\Str\Str;

var_dump(Str::make('hello dev')->upWords());
// "Hello Dev"

use ArtARTs36\Str\Str;

var_dump(Str::make('hello.dev')->explode('.'));
// ['Hello', 'Dev']

use ArtARTs36\Str\Str;

var_dump(Str::make('ABCD')->sortByChars());
// CDBA

use ArtARTs36\Str\Str;

var_dump(Str::make('BBB A DDDDD CCCC')->sortByWordsLengths());
// A BBB CCCC DDDDD

use ArtARTs36\Str\Str;

var_dump(Str::make('слово')->upFirstSymbol());
// "Слово"

use ArtARTs36\Str\Str;

var_dump(Str::make('hello.dev')->sentences());
// ['hello', 'dev']

use ArtARTs36\Str\Str;

var_dump(Str::make('hello.dev')->containsAny([
    'dev',
]));
// true

use ArtARTs36\Str\Str;

var_dump(Str::make('hello.dev')->containsAll([
    'dev',
    'hello',
]));
// true

use ArtARTs36\Str\Str;

var_dump(Str::random());
// random string

use ArtARTs36\Str\Str;

var_dump(Str::randomFix(12));
// random string 12 length

use ArtARTs36\Str\Str;

var_dump(Str::make('Hello')->shuffle());

use ArtARTs36\Str\Str;

var_dump(Str::make('hello.dev')->getBytes());
// [72, 101, 108, 108, 111]

use ArtARTs36\Str\Str;

var_dump(Str::make('hello.dev')->startsWith('hello'));
// true

use ArtARTs36\Str\Str;

var_dump(Str::make('hello.dev')->endsWith('dev'));
// true

use ArtARTs36\Str\Str;

var_dump(Str::make('Hello')->hashCode());
// 69609650

use ArtARTs36\Str\Str;

var_dump(Str::make('123')->isDigit());
// true

use ArtARTs36\Str\Str;

var_dump(Str::make('Test')->resize(5));
// 0Test

use ArtARTs36\Str\Str;

var_dump(Str::make('Test')->swapCase());
// tEST

use ArtARTs36\Str\Str;

var_dump(Str::make('Artem')->hasUppercaseSymbols()); // true
var_dump(Str::make('artem')->hasUppercaseSymbols()); // false

use ArtARTs36\Str\Str;

var_dump(Str::make('Artem')->hasLowercaseSymbols()); // true
var_dump(Str::make('ARTEM')->hasLowercaseSymbols()); // false