PHPackages                             robertaodj/str - 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. robertaodj/str

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

robertaodj/str
==============

A modern PHP string manipulation library with fluent interface and extensive functionality

v1.0.2(9mo ago)046MITPHPPHP &gt;=8.2

Since Aug 2Pushed 9mo agoCompare

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

READMEChangelogDependencies (5)Versions (4)Used By (0)

Str - Modern PHP String Manipulation Library
============================================

[](#str---modern-php-string-manipulation-library)

[![Latest Version](https://camo.githubusercontent.com/de7d53833974488dc61c1f94e3c06c98a5a72c45f24786c59fa8d3066ba00ca2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f62657274616f646a2f7374722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robertaodj/str)[![PHP Version](https://camo.githubusercontent.com/5f4e290721d019604285aca87fdd5a9a636c3c6b52a668abf5d2e4c82c2fa806/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f62657274616f646a2f7374722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robertaodj/str)[![Total Downloads](https://camo.githubusercontent.com/296b28ed428321d9ac169cb6d58b1e907cc86f154dcb1c39c1f4176b6a80a5d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f62657274616f646a2f7374722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robertaodj/str)[![License](https://camo.githubusercontent.com/9d9a81f0b6b78201ded15e9df325e15fa28b86e211d8f04386b688c5af62bee5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f726f62657274616f646a2f7374722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/robertaodj/str)

A modern, fluent PHP library for string manipulation with extensive functionality inspired by Laravel's Str class and enhanced with additional features for Brazilian Portuguese development.

[🇧🇷 Versão em Português](docs/README-pt.md) | [📖 English Documentation](docs/README-en.md)

Features
--------

[](#features)

- 🔄 **Fluent Interface**: Chain methods for readable and maintainable code
- 🌍 **Internationalization**: Built-in support for Portuguese and English
- 🚀 **Modern PHP**: Requires PHP 8.2+ with full type declarations
- 📱 **Brazilian Helpers**: CPF, CNPJ, phone formatting and validation
- 🔧 **Laravel-inspired**: Methods compatible with Laravel's Str class
- 🧪 **Well-tested**: Comprehensive test suite
- 📚 **Well-documented**: Extensive documentation with examples

📖 When to use get() and when it's optional
------------------------------------------

[](#-when-to-use-get-and-when-its-optional)

### ✅ **NO need for get()** (automatic conversion):

[](#-no-need-for-get-automatic-conversion)

- Echo and print: `echo Str::of('hello')->upper()`
- Concatenation: `"Result: " . Str::of('test')->title()`
- Interpolation: `"Value: $str"`
- Comparisons: `if ($str == 'expected')`
- Direct assignments: `$var = Str::of('test')->lower()`

### ⚠️ **Needs explicit cast** `(string)`:

[](#️-needs-explicit-cast-string)

- PHP functions: `strlen((string) $str)`
- PHP functions: `empty((string) $str)`
- Arrays: `['key' => (string) $str]`
- JSON: `json_encode(['key' => (string) $str])`

### 🔧 **Always works** with `get()`:

[](#-always-works-with-get)

- When in doubt, use `.get()` at the end
- To ensure full compatibility
- In contexts where string type is mandatory

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

[](#installation)

```
composer require robertaodj/str
```

Quick Start
-----------

[](#quick-start)

```
use Robertaodj\Str\Str;

// Create a string instance
$result = Str::of("  Hello World!  ")
    ->trim()
    ->lower()
    ->studly()
    ->get(); // "HelloWorld!"

// Static methods
echo Str::slug("Olá Mundo"); // "ola-mundo"
echo Str::kebab("HelloWorld"); // "hello-world"
echo Str::mask("12345678901", "###.###.###-##"); // "123.456.789-01"
```

Examples
--------

[](#examples)

### Basic String Manipulation

[](#basic-string-manipulation)

```
use Robertaodj\Str\Str;

// Text cleaning and formatting
$text = Str::of("  Texto com acentos e símbolos!@#  ")
    ->trim()
    ->removeAccents()
    ->alphanumeric(' ')
    ->title()
    ->get(); // "Texto Com Acentos E Simbolos"

// Case conversions
echo Str::camel("hello-world"); // "helloWorld"
echo Str::snake("HelloWorld"); // "hello_world"
echo Str::studly("hello_world"); // "HelloWorld"
```

### Brazilian Portuguese Features

[](#brazilian-portuguese-features)

```
// Document formatting
echo Str::mask("12345678901", "cpf"); // "123.456.789-01"
echo Str::mask("12345678000195", "cnpj"); // "12.345.678/0001-95"

// Capitalization with Portuguese rules
echo Str::of("o gato subiu no telhado da casa")
    ->capitalize('pt')
    ->get(); // "O Gato Subiu no Telhado da Casa"
```

### Advanced Features

[](#advanced-features)

```
// Content validation
$html = "Hello World";
echo Str::of($html)->isHtml()->get(); // true
echo Str::of($html)->stripTags()->get(); // "Hello World"

// Text truncation
$longText = "Lorem ipsum dolor sit amet...";
echo Str::of($longText)->limit(10)->get(); // "Lorem ipsu..."
echo Str::of($longText)->words(3)->get(); // "Lorem ipsum dolor..."
```

Available Methods
-----------------

[](#available-methods)

### Validation Methods

[](#validation-methods)

- `isEmail()` - Check if string is a valid email
- `isHtml()` - Check if string contains HTML tags
- `isJson()` - Check if string is valid JSON
- `isXml()` - Check if string is valid XML
- `isSerialized()` - Check if string is serialized
- `isUrl()` - Check if string is a valid URL
- `isUuid()` - Check if string is a valid UUID

### Transformation Methods

[](#transformation-methods)

- `camel()` - Convert to camelCase
- `studly()` - Convert to StudlyCase
- `snake()` - Convert to snake\_case
- `kebab()` - Convert to kebab-case
- `slug()` - Create URL-friendly slug
- `title()` - Convert to Title Case
- `upper()` - Convert to UPPERCASE
- `lower()` - Convert to lowercase

### Filtering Methods

[](#filtering-methods)

- `alphanumeric()` - Keep only alphanumeric characters
- `numeric()` - Keep only numbers
- `alpha()` - Keep only letters
- `removeAccents()` - Remove accents and diacritics
- `stripTags()` - Remove HTML/XML tags

### Formatting Methods

[](#formatting-methods)

- `mask()` - Apply formatting masks (CPF, CNPJ, phone, etc.)
- `pad()` - Pad string to specified length
- `trim()` - Remove whitespace from both ends
- `truncate()` - Truncate to specified length
- `words()` - Limit to specified number of words

Documentation
-------------

[](#documentation)

- [📖 Complete API Documentation](docs/api.md)
- [🔧 Usage Examples](docs/examples.md)
- [🚀 Migration Guide](docs/migration.md)
- [🇧🇷 Documentação em Português](docs/README-pt.md)

Testing
-------

[](#testing)

```
# Run tests
composer test

# Run tests with coverage
composer test-coverage

# Fix code style
composer cs-fix

# Run static analysis
composer phpstan
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Credits
-------

[](#credits)

- [Robert D Jesus](https://github.com/robertaodj)
- Based on [Simpla Components Str](https://github.com/simpla-components/str)
- Inspired by [Laravel's Str class](https://laravel.com/docs/strings)
- [All Contributors](../../contributors)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance56

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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 ~0 days

Total

3

Last Release

289d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c932477d76b2ff44b950712621670d2bf622ee822a7baa354cba7dce442e0f1?d=identicon)[robertaodj](/maintainers/robertaodj)

---

Tags

helperstringmanipulationfluentphp8

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/robertaodj-str/health.svg)

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

###  Alternatives

[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)[samrap/acf-fluent

A fluent interface for the Advanced Custom Fields WordPress plugin

28656.0k4](/packages/samrap-acf-fluent)[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38425.4k](/packages/bocharsky-bw-arrayzy)[statamic/stringy

A string manipulation library with multibyte support, forked from @statamic

234.5M14](/packages/statamic-stringy)[hallindavid/manny

a package of manipulators that hopefully come in useful for those of us who always forget regex when we need it (manny is short for manipulation)

38103.3k2](/packages/hallindavid-manny)

PHPackages © 2026

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