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

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

bit3/string-builder
===================

Java like StringBuilder implementation for PHP

2.0.0(11y ago)23.2k↑15.4%23MITPHPPHP &gt;=5.3

Since Dec 17Pushed 11y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (3)Used By (3)

StringBuilder for PHP
=====================

[](#stringbuilder-for-php)

[![Version](https://camo.githubusercontent.com/fd1cbb54ccab974703db444be5938b9b49f76b31611d497585b0ec9a76683a94/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626974332f737472696e672d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bit3/string-builder)[!\[Stable Build Status\](http://img.shields.io/travis/bit3/string-builder/master.svg?style=flat-square&amp;label=stable build)](https://travis-ci.org/bit3/string-builder)[!\[Upstream Build Status\](http://img.shields.io/travis/bit3/string-builder/develop.svg?style=flat-square&amp;label=dev build)](https://travis-ci.org/bit3/string-builder)[![License](https://camo.githubusercontent.com/906e7f565b8205eeed83585724c09079be20e6cd2f079371a0c196c4989ce4bd/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626974332f737472696e672d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](http://spdx.org/licenses/LGPL-3.0+)[![Downloads](https://camo.githubusercontent.com/2b527fa6ae1f9bb7db9f24a0ae12790e46cd1d434c67a8c182a67bfb9426b933/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626974332f737472696e672d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bit3/string-builder)

The benefit of StringBuilder for PHP is to provide a mutable, object oriented string and all required methods to manipulate the string, following the Java StringBuilder.

How to use
----------

[](#how-to-use)

Basic usage:

```
$stringBuilder = new StringBuilder();
$stringBuilder->append('Hello world!');
echo $stringBuilder;
```

Work with encoding:

```
// set encoding on initialisation
$stringBuilder = new StringBuilder(null, 'ISO-8859-1');

// set encoding after initialisation (will not convert contents)
$stringBuilder->setEncoding('ISO-8859-15');

// change encoding and convert contents
$stringBuilder->changeEncoding('UTF-16');
```

Check contents:

```
// string start with...
if ($stringBuilder->startsWith('Hello')) { ... } // bool(true)

// string ends with...
if ($stringBuilder->endsWith('world!')) { ... } // bool(true)

// string contains...
if ($stringBuilder->contains('Hello')) { ... } // bool(true)

// search substring from the beginning
$pos = $stringBuilder->indexOf('o w'); // int(4)

// search substring from the ending
$pos = $stringBuilder->lastIndexOf('o w'); // int(4)

// get a char from a specific position
$char = $stringBuilder->charAt(6); // string("w")

// get a substring
$substring = $stringBuilder->substring(6, 10); // string("world")

// get length of the current sequence
$length = $stringBuilder->length(); // int(11)
```

Manipulate contents:

```
// append content
$stringBuilder->append('The end is near!'); // string("Hello world!The end is near!")

// insert content
$stringBuilder->insert(12, ' I know: '); // string("Hello world! I know: The end is near!")

// replace partial content
$stringBuilder->replace(13, 14, 'You'); // string("Hello world! You know: The end is near!")

// delete substring
$stringBuilder->delete(13, 22); // string("Hello world! The end is near!")

// delete single character
$stringBuilder->deleteCharAt(11); // string("Hello world The end is near!")

// limit the length of the string
$stringBuilder->setLength(11); // string("Hello world")

// extend string to a specific length
$stringBuilder->setLength(14, '!'); // string("Hello world!!!")

// trim contents
$stringBuilder->trim('!'); // string("Hello world")
$stringBuilder->trimLeft('He'); // string("llo world")
$stringBuilder->trimRight('dl'); // string("llo wor")

// reverse content
$stringBuilder->reverse(); // string("row oll")
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4210d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e61f74ea186c1e79e072b2974ccdeef39414730476d5a8adac501eb9449b2a3?d=identicon)[tril](/maintainers/tril)

---

Top Contributors

[![tristanlins](https://avatars.githubusercontent.com/u/343404?v=4)](https://github.com/tristanlins "tristanlins (19 commits)")

---

Tags

string

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/bit3-string-builder/health.svg)](https://phpackages.com/packages/bit3-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.1k417.9M1.7k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.2M192](/packages/danielstjules-stringy)[spatie/string

String handling evolved

5604.6M24](/packages/spatie-string)[kwn/number-to-words

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

4265.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)[opis/string

Multibyte strings as objects

7424.5M8](/packages/opis-string)

PHPackages © 2026

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