PHPackages                             guillaumetissier/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. guillaumetissier/string

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

guillaumetissier/string
=======================

Small immutable PHP string helper library (UTF-8 safe).

1.0.0(4mo ago)00MITPHPPHP &gt;=8.1

Since Jan 4Pushed 4mo agoCompare

[ Source](https://github.com/guillaumetissier/string)[ Packagist](https://packagist.org/packages/guillaumetissier/string)[ RSS](/packages/guillaumetissier-string/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

guillaumetissier/string
=======================

[](#guillaumetissierstring)

PHP string utilities providing both **mutable** and **immutable** string objects with UTF-8 safe helpers.

This library offers two complementary string abstractions:

- `StrImmutable` — an immutable string value object
- `Str` — a mutable string helper with fluent API

Both share the same transformation methods and behavior.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- `ext-iconv`

Installation
------------

[](#installation)

```
composer require guillaumetissier/string
```

Which class should I use?
-------------------------

[](#which-class-should-i-use)

### StrImmutable (recommended)

[](#strimmutable-recommended)

Use `StrImmutable` when you want:

- predictability
- value object semantics
- no side effects

```
use Guillaumetissier\String\StrImmutable;

$original = StrImmutable::of('Hello World');

$slug = $original->slug();

echo $original; // Hello World
echo $slug;     // hello-world
```

Each method returns a **new instance**.

### Str (mutable)

[](#str-mutable)

Use `Str` when you want:

- in-place transformations
- fluent chaining without creating new objects
- scripting or performance-oriented usage

```
use Guillaumetissier\String\Str;

$str = Str::of('Hello World')->lower()->replace(' ', '-');

echo $str; // hello-world
```

All methods modify the internal value and return `$this`.

Common API
----------

[](#common-api)

Both classes expose the same public methods.

### Creation &amp; access

[](#creation--access)

```
::of(string $value)
->value(): string
(string) $str
```

### Length &amp; state

[](#length--state)

```
->length(): int          // UTF-8 safe
->isEmpty(): bool
->isNotEmpty(): bool
```

### Case &amp; trimming

[](#case--trimming)

```
->trim()
->lower()
->upper()
->lowerFirst()
->upperFirst()
->snake()   // snake_case
->camel()   // camelCase
->kebab()   // kebab-case
```

### Search

[](#search)

```
->startsWith(string $needle): bool
->endsWith(string $needle): bool
->contains(string $needle): bool
```

### Replace

[](#replace)

```
->replace(string $search, string $replace)
```

### Substrings

[](#substrings)

```
->substr(int $start, ?int $length = null)
```

### Padding

[](#padding)

```
->pad(int $length, string $pad = ' ', int $type = STR_PAD_RIGHT)
```

Supports `STR_PAD_LEFT`, `STR_PAD_RIGHT`, `STR_PAD_BOTH`.

### Slug

[](#slug)

```
->slug(string $separator = '-')
```

Creates a URL-friendly ASCII slug.

### Comparison

[](#comparison)

```
->equals(string|StrInterface $other): bool
```

### JSON serialization

[](#json-serialization)

Both classes implement `JsonSerializable`.

```
json_encode(StrImmutable::of('test')); // "test"
json_encode(Str::of('test'));          // "test"
```

Design principles
-----------------

[](#design-principles)

- No global helper functions
- UTF-8 safe where applicable
- No framework dependency
- Explicit mutability
- Small, focused API

License
-------

[](#license)

MIT © Guillaume Tissier

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance76

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

132d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/295253ce7789fa9279c56ac58b2d42bd808f97bb7f312fa2c78e2e782a31cfaf?d=identicon)[guillaume.tissier](/maintainers/guillaume.tissier)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

PHPackages © 2026

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