String Wrapper

2.7.0 2023-09-13 19:52 UTC

README

PHP Composer License: MIT Total Downloads

This package provides string wrapper for PHP.

Installation:

Run composer require artarts36/str

Str::chars():

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) "а"
//}

Str::count():

use ArtARTs36\Str\Str;

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

Str::toLower():

use ArtARTs36\Str\Str;

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

Str::positions():

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]

Str::reverse():

use ArtARTs36\Str\Str;

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

Str::append():

use ArtARTs36\Str\Str;

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

Str::prepend():

use ArtARTs36\Str\Str;

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

Str::equals

use ArtARTs36\Str\Str;

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

Str::deleteLastSymbol

use ArtARTs36\Str\Str;

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

Str::deleteFirstSymbol

use ArtARTs36\Str\Str;

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

Str::delete

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"

Str::trim

use ArtARTs36\Str\Str;

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

Iterable

use ArtARTs36\Str\Str;

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

Str::words

use ArtARTs36\Str\Str;

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

Str::isEmpty()

use ArtARTs36\Str\Str;

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

Str::usingLetters()

use ArtARTs36\Str\Str;

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

Str::getLettersStat()

use ArtARTs36\Str\Str;

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

Str::upWords()

use ArtARTs36\Str\Str;

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

Str::explode()

use ArtARTs36\Str\Str;

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

Str::sortByChars()

use ArtARTs36\Str\Str;

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

Str::sortByWordsLengths()

use ArtARTs36\Str\Str;

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

Str::upFirstSymbol()

use ArtARTs36\Str\Str;

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

Str::sentences()

use ArtARTs36\Str\Str;

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

Str::containsAny()

use ArtARTs36\Str\Str;

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

Str::containsAll()

use ArtARTs36\Str\Str;

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

Str::random()

use ArtARTs36\Str\Str;

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

Str::randomFix()

use ArtARTs36\Str\Str;

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

Str::shuffle()

use ArtARTs36\Str\Str;

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

Str::getBytes()

use ArtARTs36\Str\Str;

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

Str::startsWith()

use ArtARTs36\Str\Str;

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

Str::endsWith()

use ArtARTs36\Str\Str;

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

Str::hashCode()

use ArtARTs36\Str\Str;

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

Str::isDigit()

use ArtARTs36\Str\Str;

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

Str::resize()

use ArtARTs36\Str\Str;

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

Str::swapCase()

use ArtARTs36\Str\Str;

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

Str::hasUppercaseSymbols()

use ArtARTs36\Str\Str;

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

Str::hasLowercaseSymbols()

use ArtARTs36\Str\Str;

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