artarts36 / str
String Wrapper
Installs: 1 650
Dependents: 6
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.3
- ext-mbstring: *
- artarts36/empty-contracts: ^0.1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.0
- phpstan/phpstan: ^1.3
- phpunit/phpunit: ^9.3
- 2.x-dev
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.15
- 2.0.14
- 2.0.13
- 2.0.12
- 2.0.11
- 2.0.10
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.x-dev
- 1.4.0
- 1.3.18
- 1.3.17
- 1.3.16
- 1.3.15
- 1.3.14
- 1.3.13
- 1.3.12
- 1.3.11
- 1.3.10
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-use-mr-linter
- dev-optimize
- dev-algs
- dev-doc
This package is auto-updated.
Last update: 2024-11-13 22:31:03 UTC
README
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