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

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

mscribellito/str
================

Str is an immutable PHP class that provides convenient, object-oriented operations for string handling and manipulation.

v2.0(7y ago)026MITPHP &gt;=7.0.0

Since Jun 22Compare

[ Source](https://github.com/mscribellito/Str)[ Packagist](https://packagist.org/packages/mscribellito/str)[ Docs](https://github.com/mscribellito/Str)[ RSS](/packages/mscribellito-str/feed)WikiDiscussions Synced today

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

```
   _____  _
  / ____|| |
 | (___  | |_  _ __
  \___ \ | __|| '__|
  ____) || |_ | |
 |_____/  \__||_|

```

[![Latest Version on Packagist](https://camo.githubusercontent.com/aeb78a2912d88819f2fd883754099635eb8f4f87f6d61ffb4f36c7849ac3b756/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d7363726962656c6c69746f2f7374722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mscribellito/str)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/daf9b9dd2b5b2382844df299ae350d1ca7093ad6a57cf3d61dc23a50aa760fee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d7363726962656c6c69746f2f7374722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mscribellito/str)

What is Str?
------------

[](#what-is-str)

**Str** is an immutable PHP class that provides convenient, object-oriented operations for string handling and manipulation. Str provides methods for examining individual characters of the string, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. A Str is immutable (constant) and its value cannot be changed after creation.

*Note:* **Str** is not intended to replace all instances of your string variables - just those of which require many string operations and can benefit from an easy to use API.

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

[](#requirements)

PHP version 7 or newer is required.

Installing
----------

[](#installing)

Install via Composer:

```
composer require mscribellito/str

```

Require:

```
require 'path/to/Str.php';
```

Example Usage
-------------

[](#example-usage)

```
$lipsum = new Str("Lorem ipsum dolor sit amet");
$search = "ipsum";
if ($lipsum->contains($search)) {
    printf("'%s' contains '%s'", $lipsum, $search);
    // 'Lorem ipsum dolor sit amet' contains 'ipsum'
}
```

You can also create an instance of Str via a convenient, helper function:

```
$lipsum = Str("Lorem ipsum dolor sit amet");
```

Chaining
--------

[](#chaining)

```
$str = new Str('php');
echo $str->toUpperCase()->concat(' is a popular general-purpose scripting language');
// PHP is a popular general-purpose scripting language
```

Constructor Summary
-------------------

[](#constructor-summary)

Constructor and Description`Str()`
Initializes a newly created Str object so that it represents an empty character sequence.`Str(mixed $original)`
Initializes a newly created Str object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string.`Str(mixed $original, int $offset, int $count)`
Initializes a newly created Str object so that it contains characters from a substring of the argument string.Method Summary
--------------

[](#method-summary)

Modifier and TypeMethod and Description`string``__toString()`
The value of this string is returned.`string``charAt(int $index)`
Returns the character at the specified index.`int``charCodeAt(int $index)`
Returns the character ASCII value at the specified index.`int``compareTo(string $str)`
Compares two strings lexicographically.`int``compareToIgnoreCase(string $str)`
Compares two strings lexicographically, ignoring case differences.`Str``concat()`
Concatenates the specified string(s) to the end of this string.`bool``contains(string $str)`
Returns true if and only if this string contains the specified string.`bool``endsWith(string $suffix)`
Tests if this string ends with the specified suffix.`bool``equals(string $str)`
Compares this string to the specified string.`bool``equalsIgnoreCase(string $str)`
Compares this string to the specified string, ignoring case considerations.`static` `Str``format(string $format)`
Returns a formatted string using the specified format string and arguments.`int``indexOf(string $str, [int $fromIndex=0])`
Returns the index within this string of the first occurrence of the specified string, optionally starting the search at the specified index.`bool``isEmpty()`
Returns true if and only if `length()` is 0.`static` `Str``join(string $delimiter, mixed[] $elements)`
Returns a new string composed of array elements joined together with the specified delimiter.`int``lastIndexOf(string $str, [int $fromIndex=0])`
Returns the index within this string of the last occurrence of the specified character, optionally starting the search at the specified index.`int``length()`
Returns the length of this string.`bool``matches(string $regex)`
Tells whether or not this string matches the given regular expression.`bool``regionMatches(int $toffset, string $str, int $ooffset, int $length, [bool $ignoreCase=false])`
Tests if two string regions are equal.`Str``replace(string $target, string $replacement)`
Returns a string resulting from replacing all occurrences of target in this string with replacement.`Str``replaceAll(string $regex, string $replacement)`
Replaces each substring of this string that matches the given regular expression with the given replacement.`Str``replaceFirst(string $regex, string $replacement)`
Replaces the first substring of this string that matches the given regular expression with the given replacement.`Str[]``split(string $regex, [int $limit=null])`
Splits this string around matches of the given regular expression.`bool``startsWith(string $prefix, [int $toffset=0])`
Tests if this string starts with the specified prefix, optionally starting the search at the specified index.`Str``substring(int $beginIndex, [int $endIndex=null])`
Returns a string that is a substring of this string.`string[]``toCharArray()`
Converts this string to a new character array.`Str``toLowerCase()`
Converts all of the characters in this string to lower case.`Str``toUpperCase()`
Converts all of the characters in this string to upper case.`Str``trim([string $characterMask=" \t\n\r\0\x0B"])`
Returns a string whose value is this string, with any leading and trailing whitespace removed.Testing
-------

[](#testing)

Run tests with `vendor/bin/phpunit`

License
-------

[](#license)

Released under the [MIT License](https://opensource.org/licenses/MIT). See [LICENSE](LICENSE) for details.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Total

4

Last Release

2607d ago

Major Versions

v0.2-beta → v1.02016-07-26

v1.0 → v2.02019-05-11

PHP version history (2 changes)v0.1-alphaPHP &gt;=5.3.0

v2.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/505736?v=4)[Michael Scribellito](/maintainers/mscribellito)[@mscribellito](https://github.com/mscribellito)

---

Tags

stringstr

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k417.9M1.7k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.2M192](/packages/danielstjules-stringy)[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4285.3M23](/packages/kwn-number-to-words)[coduo/php-to-string

Simple library that converts PHP value into strings

26913.1M13](/packages/coduo-php-to-string)[pragmarx/ia-str

Laravel Illuminate Agnostic Str

523.5M5](/packages/pragmarx-ia-str)[opis/string

Multibyte strings as objects

7424.5M8](/packages/opis-string)

PHPackages © 2026

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