PHPackages                             gtmassey/thread - 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. gtmassey/thread

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

gtmassey/thread
===============

A framework-agnostic helper library for easily manipulating Strings in PHP.

v0.2-alpha(2y ago)00[1 PRs](https://github.com/gtmassey/thread/pulls)MITPHPPHP ^8.1CI passing

Since Dec 8Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/gtmassey/thread)[ Packagist](https://packagist.org/packages/gtmassey/thread)[ Docs](https://github.com/gtmassey/thread)[ GitHub Sponsors](https://github.com/gtmassey)[ RSS](/packages/gtmassey-thread/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (4)Versions (4)Used By (0)

Thread.php
==========

[](#threadphp)

[![Latest Version on Packagist](https://camo.githubusercontent.com/130c3644c25dd664fb6851c58c4a9e6849f5f8e3a653cc50567f49bae2e19d6f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67746d61737365792f7468726561642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gtmassey/thread)[![Tests](https://camo.githubusercontent.com/dc8fc0ec00c6689cc093e897e1fd174aea4febd703e542c4da39f19fae960243/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f67746d61737365792f5468726561642f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/gtmassey/Thread/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/6ce2f2a406b68eeb8862bb0edfcfc8a469dd62d130628d4d016910ded4eb1bfe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67746d61737365792f7468726561642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gtmassey/thread)

Wrapper class for string manipulation in PHP.

Never slog through the php string function docs again!

> Note from the developer:
>
> This package is still in *active* development, and is *NOT* fully tested or ready for production use. This release is an alpha release (at best) and you can expect some kind of breaking change before a full v1 release. If you have any suggestions for features, please feel free to open an issue or a pull request.
>
> Thanks,
>
> Garrett

I've worked with PHP for... a little over 10 years now, and I've always hated the existing string functions. They are certainly plentiful, and if you know your regex, you can do a lot with them, but they are not very intuitive, and the naming conventions are... bad.

Laravel's String helper classes are a gigantic leap in the right direction (IMO), but it's wrapped in the Laravel framework, and while you can use it outside of Laravel, I'd rather see a dedicated third party library that is framework-agnostic.

Thread is a framework-agnostic, static-method focused wrapper class for easily manipulating strings in PHP. No more calling random functions with random arguments and hoping for the best. Instead, create a new Thread object, and manipulate the underlying string by chaining methods together in an elegant and fluent way.

Why Thread?
-----------

[](#why-thread)

Originally, I wanted to call this package "Twine", but while working on an alpha version, I stumbled across the [PHLAK/twine](https://github.com/PHLAK/twine) package, which accomplishes the exact same thing I was trying to do, and does it well.

So, instead of a play on words from my farming origins (Twine being a synonym for string, and a tool we used for everything on the farm), I decided to go with a play on words from my mother's hobby of sewing and quilting. So, "string" from computer science, meet "thread" from fiber arts.

Not to be confused with "thread" as in the singular process that runs on a CPU... that's a different thing entirely.

Plus, 'string' is a reserved word in PHP, so I couldn't use that anyway.

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

[](#installation)

You can install the package via composer:

```
composer require gtmassey/thread
```

Usage
-----

[](#usage)

### Getting started

[](#getting-started)

The package is a simple PHP package, so you can use it in any PHP project. Simply add it to your use statements, and you're ready to go.

```
use Gtmassey\Thread\Thread;
```

If you are using Laravel, the `ThreadServiceProvider` will automatically register the `Thread` facade for you. You can use the facade in your code like this:

```
use Thread;
```

Now you can use the `Thread::make()` method to create a new Thread object from a string or an array.

If you are using Symfony, you can use the `Thread` class directly, or you can use the `ThreadFacade` class.

If you aren't using any of these frameworks, don't worry. You can just include the Thread class in your code and use it directly without any issues.

### Creating a Thread object

[](#creating-a-thread-object)

You can use the `new` keyword to create a new Thread object, the constructor accepts a string or null as an argument. If null, the default is an empty string `""`.

```
$string = new Thread('Hello world!');
echo($string->toString());
// "Hello world!"

$emptyString = new Thread();
echo($emptyString->toString());
// ""
```

You can also use the static `make()`, `of()`, and `from()` methods to create a new Thread object from either a string or an array. Each of the static construction methods accepts either a string OR an array as an argument.

If you use an array as the argument for the static construction methods, the array will be imploded with a space as the separator always. You can use StringableTrait methods to then manipulate the string to your liking.

```
$string = Thread::make('a b c');
//OR
$string = Thread::make(['a', 'b', 'c']);
echo($string->toString());
// "Hello world!"

$string = Thread::of('a b c');
//OR
$string = Thread::of(['a', 'b', 'c']);
echo($string->toString());
// "a b c"

$string = Thread::from('a b c');
//OR
$string = Thread::from(['a', 'b', 'c']);
echo($string->toString());
// "a b c"
```

### Manipulating strings

[](#manipulating-strings)

Thread comes with several methods for manipulating strings. Methods that live in the `StringableTrait` trait are chainable. Methods that live in the Thread.php class are not chainable, but instead return a specific value, like a string or an array.

[Available Stringable Methods](docs/stringable-methods.md)

Example of chaining methods to manipulate a string:

```
$string = Thread::from('Foo bar');
//"Foo bar"
$string->toPascalCase();
//"FooBar"
$string->append(' baz');
//"FooBar baz"
$string->toTitleCase()->stripChar('a')->lcFirst()
//"fooBr Bz
$string->stripWhitespace()->stripChar('o');
//fBrBz
```

```
//example: manipulating phone number string:
$phoneNumber = Thread::from('+1 (123) 456-7890 x123');
$phone = $phoneNumber->splitOn('x')[0];
//"+1 (123) 456-7890 "
$extension = $phoneNumber->splitOn('x')[1];
//"123"
$phone->stripNonNumeric()->stripWhitespace()->toString();
//"11234567890"
$phone->getIntegerValue();
//11234567890
```

Testing
-------

[](#testing)

To run the testsuite, run the following command:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Garrett Massey](https://github.com/gtmassey)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 97.7% 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

937d ago

### Community

Maintainers

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

---

Top Contributors

[![gtmassey](https://avatars.githubusercontent.com/u/109831143?v=4)](https://github.com/gtmassey "gtmassey (43 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

phplibrarystringsstring manipulationThreadString helpersgtmassey

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gtmassey-thread/health.svg)

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

PHPackages © 2026

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