PHPackages                             chroma-x/string-builder - 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. chroma-x/string-builder

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

chroma-x/string-builder
=======================

A string builder library providing different string methods written in PHP.

1.1.0(1y ago)41.4k41MITPHPPHP &gt;=5.4CI failing

Since Aug 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/chroma-x/php-string-builder)[ Packagist](https://packagist.org/packages/chroma-x/string-builder)[ Docs](https://chroma-x.de/)[ RSS](/packages/chroma-x-string-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (1)

PHP String Builder
==================

[](#php-string-builder)

[![Build Status](https://camo.githubusercontent.com/06671f8b4b4132b34a94b2220ffe9359d0335ea9dd9bef8652f0a4994e71e81d/68747470733a2f2f7472617669732d63692e6f72672f6368726f6d612d782f7068702d737472696e672d6275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/chroma-x/php-string-builder)[![Test Coverage](https://camo.githubusercontent.com/2b4b55824f78a3f40888100c712ae02fa8ee47eeca94c2fd847e5a2c8439393f/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6368726f6d612d782f7068702d737472696e672d6275696c6465722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/chroma-x/php-string-builder/coverage)[![Dependency Status](https://camo.githubusercontent.com/3c6f330933d741b7257200881fc538cca32bb1b530c64f3da861e6f813eecc3a/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3537616133336164663237636332303035303130326630652f62616467652e737667)](https://www.versioneye.com/user/projects/57aa33adf27cc20050102f0e)[![SensioLabs Insight](https://camo.githubusercontent.com/2d4e25d78c150f21e4ce762fa1012f4ab573f3c4749ab29e3107720974c2513a/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f65633336393137642d626161312d343832632d383931362d3431653261326334386435632e737667)](https://insight.sensiolabs.com/projects/ec36917d-baa1-482c-8916-41e2a2c48d5c)[![Code Climate](https://camo.githubusercontent.com/7fa4f19dcfd60502643ba7bfe44f65189021980f69b2996319a62a7686677029/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6368726f6d612d782f7068702d737472696e672d6275696c6465722f6261646765732f6770612e737667)](https://codeclimate.com/github/chroma-x/php-string-builder)[![Latest Stable Version](https://camo.githubusercontent.com/c2cc788d33ea6578941c4b0516f3ecb2d3158483c87e0eebd95c2ecbd0aefba7/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f737472696e672d6275696c6465722f762f737461626c65)](https://packagist.org/packages/chroma-x/string-builder)[![Total Downloads](https://camo.githubusercontent.com/ed12a65381d90b1af3d99e09d33990205837077addd4eddef9e228e4755b5d8c/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f737472696e672d6275696c6465722f646f776e6c6f616473)](https://packagist.org/packages/chroma-x/string-builder)[![License](https://camo.githubusercontent.com/c49c1fb5eb2d8a709148b43dac5d8b72cdb39cccb2618454098a79d3f12ef607/68747470733a2f2f706f7365722e707567782e6f72672f6368726f6d612d782f737472696e672d6275696c6465722f6c6963656e7365)](https://packagist.org/packages/chroma-x/string-builder)

A basic string builder library providing different string methods written in PHP.

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

[](#installation)

```
{
   	"require": {
        "chroma-x/string-builder": "~1.0"
    }
}

```

Usage
-----

[](#usage)

### Autoloading and namesapce

[](#autoloading-and-namesapce)

```
require_once('path/to/vendor/autoload.php');

```

### Building and modifying a string

[](#building-and-modifying-a-string)

```
use ChromaX\StringBuilder\StringBuilder;

$builder = new StringBuilder('rolod muspi meroL');
$builder
	->reverse()
	->append(' sit amet, consetetur')
	->append(12)
	->append(false)
	->prepend('b')
	->append(true)
	->insert(1, 'qäs')
	->replace(6, 2, 'wertz')
	->setCharAt(4, '2')
	->delete(0, 2)
	->delete(40)
	->deleteCharAt(3);

$result = $builder->build();
fwrite(STDOUT, ' 1. Built string                                          ' . $result . PHP_EOL);

$result = $builder->buildSubstring(5, 2);
fwrite(STDOUT, ' 2. Built substring                                       ' . $result . PHP_EOL);

$result = $builder->buildSubstring(5);
fwrite(STDOUT, ' 3. Built substring                                       ' . $result . PHP_EOL);

$result = $builder->charAt(5);
fwrite(STDOUT, ' 4. Character at position 5                               ' . $result . PHP_EOL);

$result = $builder->firstChar();
fwrite(STDOUT, ' 5. First character                                       ' . $result . PHP_EOL);

$result = $builder->lastChar();
fwrite(STDOUT, ' 6. Last character                                        ' . $result . PHP_EOL);

```

will output the following

```
 1. Built string                                          ä2wertzem ipsum dolor sit amet, conset
 2. Built substring                                       rt
 3. Built substring                                       rtzem ipsum dolor sit amet, conset
 4. Character at position 5                               r
 5. First character                                       ä
 6. Last character                                        t

```

### Getting string properties

[](#getting-string-properties)

```
$result = $builder->length();
fwrite(STDOUT, ' 7. String length                                         ' . $result . PHP_EOL);

$result = $builder->size();
fwrite(STDOUT, ' 8. Number of bytes                                       ' . $result . PHP_EOL);

$result = $builder->indexOf('e');
fwrite(STDOUT, ' 9. First occurence of "e"                                ' . $result . PHP_EOL);

$result = $builder->indexOf('e', 5);
fwrite(STDOUT, '10. First occurence of "e" after position 5               ' . $result . PHP_EOL);

$result = $builder->lastIndexOf('e');
fwrite(STDOUT, '11. Last occurence of "e"                                 ' . $result . PHP_EOL);

$result = $builder->lastIndexOf('e', 5);
fwrite(STDOUT, '12. Last occurence of "e" before the 5th last character   ' . $result . PHP_EOL);

$result = $builder->contains('ipsum');
fwrite(STDOUT, '13. Whether the string contains "ipsum"                   ' . $result . PHP_EOL);

```

will output the following

```
 7. String length                                         38
 8. Number of bytes                                       39
 9. First occurence of "e"                                4
10. First occurence of "e" after position 5               8
11. Last occurence of "e"                                 37
12. Last occurence of "e" before the 5th last character   29
13. Whether the string contains "ipsum"

```

### Exception handling

[](#exception-handling)

All methods throw an `\InvalidArgumentException` if misconfigured except `indexOf` and `lastIndexOf` wich return `null` if the given subtring is not contained by the string to build.

```
use ChromaX\StringBuilder\StringBuilder;

try {
	$builder = new StringBuilder();

	$result = $builder->indexOf('a');
	fwrite(STDOUT, '1. Result                 ' . $result . PHP_EOL);

	$result = $builder->lastIndexOf('a');
	fwrite(STDOUT, '2. Result                 ' . $result . PHP_EOL);

	$result = $builder->charAt(10);
	fwrite(STDOUT, '3. Result                 ' . $result . PHP_EOL);

} catch (\InvalidArgumentException $exception) {
	fwrite(STDERR, 'Exception with message    ' . $exception->getMessage() . PHP_EOL);
}

```

will output the following

```
1. Result
2. Result
Exception with message    Position invalid

```

---

Contribution
------------

[](#contribution)

Contributing to our projects is always very appreciated.
**But: please follow the contribution guidelines written down in the [CONTRIBUTING.md](https://github.com/chroma-x/php-string-builder/blob/master/CONTRIBUTING.md) document.**

License
-------

[](#license)

PHP String Builder is under the MIT license.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

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

Every ~252 days

Recently: every ~628 days

Total

13

Last Release

546d ago

PHP version history (2 changes)1.0.0PHP &gt;=5.3

1.0.5PHP &gt;=5.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5921241?v=4)[Martin Brecht-Precht](/maintainers/bonscho)[@Bonscho](https://github.com/Bonscho)

---

Top Contributors

[![abmarkenwerk](https://avatars.githubusercontent.com/u/61745221?v=4)](https://github.com/abmarkenwerk "abmarkenwerk (1 commits)")[![Bonscho](https://avatars.githubusercontent.com/u/5921241?v=4)](https://github.com/Bonscho "Bonscho (1 commits)")

---

Tags

composer-packagephp-librarystring-builderstring-manipulationstringbuilder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chroma-x-string-builder/health.svg)

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

###  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.1k394.3M1.5k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[kwn/number-to-words

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

4235.0M21](/packages/kwn-number-to-words)[opis/string

Multibyte strings as objects

7420.9M7](/packages/opis-string)[paquettg/string-encode

Facilitating the process of altering string encoding in PHP.

698.7M43](/packages/paquettg-string-encode)

PHPackages © 2026

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