PHPackages                             chr15k/string - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chr15k/string

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chr15k/string
=============

Awesome String helpers package

1.0.5(5y ago)2661MITPHPPHP ^7.4CI failing

Since Jul 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/chr15k/string)[ Packagist](https://packagist.org/packages/chr15k/string)[ Docs](https://github.com/chr15k/string)[ RSS](/packages/chr15k-string/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (4)Versions (14)Used By (1)

Awesome String helpers for your PHP project
===========================================

[](#awesome-string-helpers-for-your-php-project)

[![Latest Stable Version](https://camo.githubusercontent.com/ecef6701629ae213885c974ebd74445575375e588e957ed08693d13683374612/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f737472696e672f76)](//packagist.org/packages/chr15k/string) [![Latest Unstable Version](https://camo.githubusercontent.com/a5f8fc07d8dbc751328fa676f988b6e57f9989bb1400e96c77406e175c1d0f12/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f737472696e672f762f756e737461626c65)](//packagist.org/packages/chr15k/string) [![Total Downloads](https://camo.githubusercontent.com/4c6878cc106a32756fc34d8db1ffdc793ab280b08d82e2b26454053e232edb3f/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f737472696e672f646f776e6c6f616473)](//packagist.org/packages/chr15k/string) [![License](https://camo.githubusercontent.com/5ddc6206eab0bc9cf98c987f0b84acedbb82362f8e0d30a71f6f1d910a2d486c/68747470733a2f2f706f7365722e707567782e6f72672f63687231356b2f737472696e672f6c6963656e7365)](//packagist.org/packages/chr15k/string)

This package provides useful helpers for working with strings in PHP, including UUID and ASCII support.

Based on ...

- Laravel's string helper work ()

Install
-------

[](#install)

You can install this package via composer:

```
composer require chr15k/string
```

Usage
-----

[](#usage)

```
return s('Child')
    ->plural()
    ->possessive()
    ->append(' Book'); // outputs: "Children's Book"

return s('Child')
    ->plural(1); // (pass a count) outputs: "Child"

return s(' hello_world')
    ->trim()
    ->camel(); // outputs: "helloWorld"

return s('Hello World')
    ->studly(); // outputs: "HelloWorld"

return s('Hello World')
    ->slug('-'); // outputs: "hello-world"
```

Docs
----

[](#docs)

 String Method Chaining```
Chain multiple string operations together using the s() helper.

```

- [after](#after2)
- [afterLast](#afterLast2)
- [append](#append2)
- [ascii](#ascii2)
- [basename](#basename2)
- [before](#before2)
- [beforeLast](#beforeLast2)
- [camel](#camel2)
- [contains](#contains2)
- [containsAll](#containsAll2)
- [dirname](#dirname2)
- [endsWith](#endsWith2)
- [exactly](#exactly2)
- [explode](#explode2)
- [finish](#finish2)
- [isAscii](#isAscii2)
- [isEmpty](#isEmpty2)
- [isNotEmpty](#isNotEmpty2)
- [kebab](#kebab2)
- [length](#length2)
- [limit](#limit2)
- [lower](#lower2)
- [ltrim](#ltrim2)
- [match](#match2)
- [plural](#plural2)
- [possessive](#possessive2)
- [prepend](#prepend2)
- [replace](#replace2)
- [replaceArray](#replaceArray2)
- [replaceFirst](#replaceFirst2)
- [replaceLast](#replaceLast2)
- [rtrim](#rtrim2)
- [singular](#singular2)
- [slug](#slug2)
- [snake](#snake2)
- [split](#split2)
- [start](#start2)
- [startsWith](#startsWith2)
- [studly](#studly2)
- [substr](#substr2)
- [title](#title2)
- [trim](#trim2)
- [ucfirst](#ucfirst2)
- [upper](#upper2)
- [whenEmpty](#whenEmpty2)
- [words](#words2)

### after

[](#after)

```
$slice = s('This is my name')->after('This is');

// ' my name'
```

### afterLast

[](#afterlast)

```
$slice = s('App\Controllers\Controller')->afterLast('\\');

// 'Controller'
```

### append

[](#append)

```
$string = s('Hello')->append(' there!');

// 'Hello there!'
```

### ascii

[](#ascii)

Transliterate the string to an ASCII value:

```
$string = s('ü')->ascii();

// 'u'
```

### basename

[](#basename)

```
$string = s('/foo/bar/baz')->basename();

// 'baz'

// If needed, you may provide an "extension" that will be removed from the trailing component:
$string = s('/foo/bar/baz.jpg')->basename('.jpg');

// 'baz'
```

### before

[](#before)

```
$slice = s('This is my name')->before('my name');

// 'This is '
```

### beforeLast

[](#beforelast)

```
$slice = s('This is my name')->beforeLast('is');

// 'This '
```

### camel

[](#camel)

```
$converted = s('foo_bar')->camel();

// fooBar
```

### contains

[](#contains)

```
$contains = s('This is my name')->contains('my');

// true

// You can also pass an array:
$contains = s('This is my name')->contains(['my', 'foo']);

// true
```

### containsAll

[](#containsall)

```
$containsAll = s('This is my name')->containsAll(['my', 'name']);

// true
```

### dirname

[](#dirname)

```
$string = s('/foo/bar/baz')->dirname();

// '/foo/bar'

// Optionally pass directory levels as second argument:
$string = s('/foo/bar/baz')->dirname(2);

// '/foo'
```

### endsWith

[](#endswith)

```
$result = s('This is my name')->endsWith('name');

// true

// You can also pass an array
$result = s('This is my name')->endsWith(['name', 'foo']);

// true

$result = s('This is my name')->endsWith(['this', 'foo']);

// false
```

### exactly

[](#exactly)

```
$result = s('Chris')->exactly('Chris');

// true

$result = s(' Chris')->exactly('Chris');

// false

$result = s('Chris')->exactly('chris');

// false
```

### explode

[](#explode)

```
$collection = s('foo bar baz')->explode(' ');

// ['foo', 'bar', 'baz']
```

### finish

[](#finish)

```
$adjusted = s('this/string')->finish('/');

// this/string/

$adjusted = s('this/string/')->finish('/');

// this/string/
```

### isAscii

[](#isascii)

```
$result = s('Chris')->isAscii();

// true

$result = s('ü')->isAscii();

// false
```

### isEmpty

[](#isempty)

```
$result = s('  ')->trim()->isEmpty();

// true

$result = s('Chris')->trim()->isEmpty();

// false
```

### isNotEmpty

[](#isnotempty)

```
$result = s('  ')->trim()->isNotEmpty();

// false

$result = s('Chris')->trim()->isNotEmpty();

// true
```

### kebab

[](#kebab)

```
$converted = s('fooBar')->kebab();

// foo-bar
```

### length

[](#length)

```
$length = s('Chris')->length();

// 5
```

### limit

[](#limit)

```
$truncated = s('The quick brown fox jumps over the lazy dog')->limit(20);

// The quick brown fox...

// pass second argument to append something other than '...'
$truncated = s('The quick brown fox jumps over the lazy dog')->limit(20, ' (...)');

// The quick brown fox (...)
```

### lower

[](#lower)

```
$result = s('CHRIS')->lower();

// 'chris'
```

### ltrim

[](#ltrim)

```
$string = s('  Chris  ')->ltrim();

// 'Chris  '

$string = s('/Chris/')->ltrim('/');

// 'Chris/'
```

### match

[](#match)

```
$result = s('foo bar')->match('/bar/');

// 'bar'

$result = s('foo bar')->match('/foo (.*)/');

// 'bar'
```

### plural

[](#plural)

```
$plural = s('car')->plural();

// cars

$plural = s('child')->plural();

// children

// Pass second argument as a count to determine singular or plural form of a string:
$plural = s('child')->plural(2);

// children

$plural = s('child')->plural(1);

// child
```

### possessive

[](#possessive)

```
$possessive = s('Chris')->possessive();

// Chris'

$possessive = s('David')->possessive();

// David's

$possessive = s('it')->possessive();

// its
```

### prepend

[](#prepend)

```
$string = s('World')->prepend('Hello ');

// Hello World
```

### replace

[](#replace)

```
$replaced = s('Hello World')->replace('World', 'Chris');

// Hello Chris
```

### replaceArray

[](#replacearray)

```
$string = 'The event will take place between ? and ?';

$replaced = s($string)->replaceArray('?', ['8:30', '9:00']);

// The event will take place between 8:30 and 9:00
```

### replaceFirst

[](#replacefirst)

```
$replaced = s('the quick brown fox jumps over the lazy dog')->replaceFirst('the', 'a');

// a quick brown fox jumps over the lazy dog
```

### replaceLast

[](#replacelast)

```
$replaced = s('the quick brown fox jumps over the lazy dog')->replaceLast('the', 'a');

// the quick brown fox jumps over a lazy dog
```

### rtrim

[](#rtrim)

```
$string = s('  Chris  ')->rtrim();

// '  Chris'

$string = s('/Chris/')->rtrim('/');

// '/Chris'
```

### singular

[](#singular)

```
$singular = s('cars')->singular();

// car

$singular = s('children')->singular();

// child
```

### slug

[](#slug)

```
$slug = s('Hello World')->slug('-');

// hello-world
```

### snake

[](#snake)

```
$converted = s('fooBar')->snake();

// foo_bar
```

### split

[](#split)

```
$segments = s('one, two, three')->split('/[\s,]+/');

// collect(["one", "two", "three"])
```

### start

[](#start)

```
$adjusted = s('this/string')->start('/');

// /this/string

$adjusted = s('/this/string')->start('/');

// /this/string
```

### startsWith

[](#startswith)

```
$result = s('This is my name')->startsWith('This');

// true
```

### studly

[](#studly)

```
$converted = s('foo_bar')->studly();

// FooBar
```

### substr

[](#substr)

```
$string = s('Hello World')->substr(6);

// World

$string = s('Hello World')->substr(6, 3);

// Wo
```

### title

[](#title)

```
$converted = s('a nice title uses the correct case')->title();

// A Nice Title Uses The Correct Case
```

### trim

[](#trim)

```
$string = s('  Chris  ')->trim();

// 'Chris'

$string = s('/Chris/')->trim('/');

// 'Chris'
```

### ucfirst

[](#ucfirst)

```
$string = s('foo bar')->ucfirst();

// Foo bar
```

### upper

[](#upper)

```
$adjusted = s('chris')->upper();

// CHRIS
```

### whenEmpty

[](#whenempty)

The whenEmpty method invokes the given Closure if the string is empty:

```
$string = s('  ')->whenEmpty(function ($string) {
    return $string->trim()->prepend('Chris');
});

// 'Chris'
```

### words

[](#words)

```
$string = s('Perfectly balanced, as all things should be.')->words(3, ' >>>');

// Perfectly balanced, as >>>
```

 String Methods- [after](#after)
- [afterLast](#afterLast)
- [before](#before)
- [camel](#camel)
- [contains](#contains)
- [containsAll](#containsAll)
- [endsWith](#endsWith)
- [finish](#finish)
- [isAscii](#isAscii)
- [isUuid](#isUuid)
- [kebab](#kebab)
- [length](#length)
- [limit](#limit)
- [lower](#lower)
- [match](#match)
- [orderedUuid](#orderedUuid)
- [plural](#plural)
- [possessive](#possessive)
- [random](#random)
- [replaceArray](#replaceArray)
- [replaceFirst](#replaceFirst)
- [replaceLast](#replaceLast)
- [singular](#singular)
- [slug](#slug)
- [snake](#snake)
- [start](#start)
- [startsWith](#startsWith)
- [studly](#studly)
- [title](#title)
- [ucfirst](#ucfirst)
- [upper](#upper)
- [uuid](#uuid)
- [words](#words)

### Str::after()

[](#strafter)

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

// ' my name'
```

### Str::afterLast()

[](#strafterlast)

```
$slice = Str::afterLast('App\Controllers\Controller', '\\');

// 'Controller'
```

### Str::before()

[](#strbefore)

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

// 'This is '
```

### Str::camel()

[](#strcamel)

```
$converted = Str::camel('foo_bar')

// fooBar
```

### Str::contains()

[](#strcontains)

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

// true
```

### Str::containsAll()

[](#strcontainsall)

```
$containsAll = Str::containsAll('This is my name', ['my', 'name']);

// true
```

### Str::endsWith()

[](#strendswith)

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

// true
```

### Str::finish()

[](#strfinish)

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

// this/string/

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

// this/string/
```

### Str::isAscii()

[](#strisascii)

```
$isAscii = Str::isAscii('Chris');

// true

$isAscii = Str::isAscii('ü');

// false
```

### Str::isUuid()

[](#strisuuid)

```
$isUuid = Str::isUuid('a0a2a2d2-0b87-4a18-83f2-2529882be2de');

// true

$isUuid = Str::isUuid('chris');

// false
```

### Str::kebab()

[](#strkebab)

```
$converted = Str::kebab('fooBar');

// foo-bar
```

### Str::length()

[](#strlength)

```
$length = Str::length('Chris');

// 5
```

### Str::limit()

[](#strlimit)

```
$truncated = Str::limit('The quick brown fox jumps over the lazy dog', 20);

// The quick brown fox...
```

### Str::lower()

[](#strlower)

```
$lower = Str::lower('CHRIS');

// chris
```

### Str::match()

[](#strmatch)

```
$matches = Str::match('foo*', 'foobar');

// true

$matches = Str::match('baz*', 'foobar');

// false
```

### Str::orderedUuid()

[](#strordereduuid)

The Str::orderedUuid() method generates a "timestamp first" UUID that may be efficiently stored in an indexed database column.

```
$orderedUuid = Str::orderedUuid();

// 90f81d6c-b4f6-4b03-a82d-800058a21705
```

### Str::plural()

[](#strplural)

```
$plural = Str::plural('bus');

// buses

$plural = Str::plural('child');

// children

// Pass second argument to retrieve the singular or plural form of the string...

$plural = Str::plural('child', 2);

// children

$plural = Str::plural('child', 1);

// child
```

### Str::possessive()

[](#strpossessive)

```
$possessive = Str::possessive('Chris');

// Chris'

$possessive = Str::possessive('David');

// David's

$possessive = Str::possessive('it');

// its
```

### Str::random()

[](#strrandom)

```
$random = Str::random(40);

// odkX5tWGo3tb8hlNgdoVPjHxZR8xRzii1uFT1cxa
```

### Str::replaceArray()

[](#strreplacearray)

```
$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
```

### Str::replaceFirst()

[](#strreplacefirst)

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

// a quick brown fox jumps over the lazy dog
```

### Str::replaceLast()

[](#strreplacelast)

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

// the quick brown fox jumps over a lazy dog
```

### Str::singular()

[](#strsingular)

```
$singular = Str::singular('cars');

// car

$singular = Str::singular('children');

// child
```

### Str::slug()

[](#strslug)

```
$slug = Str::slug('Chris The Coder', '-');

// chris-the-coder
```

### Str::snake()

[](#strsnake)

```
$converted = Str::snake('fooBar');

// foo_bar
```

### Str::start()

[](#strstart)

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

// /this/string

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

// /this/string
```

### Str::startsWith()

[](#strstartswith)

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

// true
```

### Str::studly()

[](#strstudly)

```
$converted = Str::studly('foo_bar');

// FooBar
```

### Str::title()

[](#strtitle)

```
$converted = Str::title('a nice title uses the correct case');

// A Nice Title Uses The Correct Case
```

### Str::ucfirst()

[](#strucfirst)

```
$string = Str::ucfirst('foo bar');

// Foo bar
```

### Str::upper()

[](#strupper)

```
$string = Str::upper('chris');

// CHRIS
```

### Str::uuid()

[](#struuid)

```
$uuid = Str::uuid();

// 0b1a9d6f-e2c7-489d-93f9-331108ebc314
```

### Str::words()

[](#strwords)

```
return Str::words('Perfectly balanced, as all things should be.', 3, ' >>>');

// Perfectly balanced, as >>>
```

Testing
-------

[](#testing)

You can run the tests with:

```
vendor/bin/phpunit

```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/chr15k/string/blob/master/LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

13

Last Release

2113d ago

Major Versions

0.3.0 → 1.0.02020-07-15

PHP version history (3 changes)v0.1.0PHP ^7.1

0.3.0PHP ^7.2.5

1.0.3PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/c817e814df42c78ac76505c9394a786946a0d9517b64984eca34b6f04010df95?d=identicon)[chr15k](/maintainers/chr15k)

---

Top Contributors

[![chr15k](https://avatars.githubusercontent.com/u/67823070?v=4)](https://github.com/chr15k "chr15k (2 commits)")

---

Tags

phpstringhelperschr15k

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chr15k-string/health.svg)

```
[![Health](https://phpackages.com/badges/chr15k-string/health.svg)](https://phpackages.com/packages/chr15k-string)
```

###  Alternatives

[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)[pragmarx/ia-str

Laravel Illuminate Agnostic Str

523.5M5](/packages/pragmarx-ia-str)[transprime-research/piper

PHP Pipe method execution with values from chained method executions

174.6k2](/packages/transprime-research-piper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
