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

Abandoned → [bit3/string-builder](/?search=bit3%2Fstring-builder)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

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

Java like StringBuilder implementation for PHP

1.1(12y ago)32.5k2MITPHPPHP &gt;=5.3

Since Jul 15Pushed 12y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (4)Used By (2)

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

[](#stringbuilder-for-php)

[![Build Status](https://camo.githubusercontent.com/a3d2d616b6aa674e9f15aa1a79f479032b32f023f470962bb352c8b1e3ebde3e/68747470733a2f2f6170692e7472617669732d63692e6f72672f626974332f7068702d737472696e672d6275696c6465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/bit3/php-string-builder) [![API DOCS](https://camo.githubusercontent.com/7cf81f624715e8b36d6eb16ea441abc0953962b233e4916f9b4efee5ee035d2e/687474703a2f2f61706967656e657261746f722e6f72672f62616467652e706e67)](http://bit3.github.io/php-string-builder/class-StringBuilder.html)

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

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

Every ~0 days

Total

3

Last Release

4687d 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 (17 commits)")

---

Tags

string

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/bit3-php-string-builder/health.svg)](https://phpackages.com/packages/bit3-php-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)[spatie/string

String handling evolved

5604.6M24](/packages/spatie-string)[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)[voku/stringy

A string manipulation library with multibyte support

1783.8M19](/packages/voku-stringy)

PHPackages © 2026

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