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

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

robclancy/string
================

A PHP library to manipulate strings via a string object similar to other languages

20273PHP

Since Apr 9Pushed 13y ago3 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

String
======

[](#string)

A PHP library to manipulate strings via a string object similar to other languages.

This library is designed as an alternative way to using PHP's inconsistant string functions without resorting to a simple wrapper. Basically a string object like you find in other languages. Also with a `str` function to make things a little shorter/easier and hide the longer `new String` when working with strings a lot.

This library has 2 dependencies: [oodle/inflect](https://github.com/oodle/inflect) and [patchwork/utf8](https://github.com/nicolas-grekas/Patchwork-UTF8)

Installation and Setup
----------------------

[](#installation-and-setup)

To install add the following to your `composer.json` file:

```
"robclancy/string": "dev-master"
```

Then you can use it out of the box directly with `RobClancy\String\String` or `str`. Alternatively create an alias like follows...

Native:

```
class_alias('RobClancy\String\String', 'String');
```

Laravel, add to your aliases array in `app/config/app.php`:

```
'String' => 'RobClancy\String\String',
```

Examples Note: some of these aren't implemented yet, this package won't be ready for use until I write all the tests
--------------------------------------------------------------------------------------------------------------------

[](#examples-note-some-of-these-arent-implemented-yet-this-package-wont-be-ready-for-use-until-i-write-all-the-tests)

### Class name to table name

[](#class-name-to-table-name)

```
class UserGroup {

	public function getTable()
	{
		// We might want to point to the plural, snake case version of this class
		$class = new String(__CLASS__);

		// Snake case and split
		$words = $class->snake()->split('_');

		// Pluralize last word
		// Note: at a later stage I might have an array object which will be used here to do $words->last()->plural();
		$words[count($word)-1]->plural();

		// Now return it joined back up
		return String::join($words, '_');
	}
}
```

### Ruby styled string replace and python styled slicing

[](#ruby-styled-string-replace-and-python-styled-slicing)

```
$string = new String('Jason made Basset, it is pretty cool I hear, vote 1 Jason!!');

// String replace, the same as doing the key as $search and the value as $replace in $string->replace($search, $value)
$string['Jason'] = 'Jason Lewis';
$string['Basset'] = 'Basset (Better Asset Management)';

// We now want to change the 1 into 9001 but because the array notation here is overloaded to do python style slicing
// and ruby style replacing we need to force it to the replace, we do this simply by starting the replace with 'r|'
$string['r|1'] = 9001;

// Lastly let's clean it up and make it end with a single !
$string->finish('!');
// or
$string['!!'] = '!';
// or
$string->slice(0, -1);
// or the same as above with python syntax.
$string = $string[':-1'];

echo $string;
// Outputs: "Jason Lewis made Basset (Better Asset Management), it is pretty cool I hear, vote 9001 Jason Lewis!"

// Just another example of slicing with python
$string = new String('I like pizza :D');
$pizza = $string['7:-3'];
echo $pizza; // pizza
```

### Basic and quick validation with exceptions

[](#basic-and-quick-validation-with-exceptions)

```
$string = 'Love for laravel  $word)
{
	$words[$key] = $word->upperFirst();
}

// Basically an alias for implode here
$string = String::join($words, ' ');
echo $string; // It\'s Saturday, I Shouldn\'t Be Working On This And Drinking Or Something
```

[![Build Status](https://camo.githubusercontent.com/f4a5df59c4d914c8af0693110a52d4461e1421f1fe5b2ab630ff4582830ae4ca/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f726f62636c616e63792f737472696e672e706e67)](http://travis-ci.org/robclancy/string)

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

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

---

Top Contributors

[![robclancy-test](https://avatars.githubusercontent.com/u/123053691?v=4)](https://github.com/robclancy-test "robclancy-test (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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