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

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

atk14/string-buffer
===================

StringBuffer is a PHP class providing operations for efficient string buffering

v1.2.6(2mo ago)131.7k↑104.4%15MITPHPPHP &gt;=5.6.0CI passing

Since Jan 24Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/atk14/StringBuffer)[ Packagist](https://packagist.org/packages/atk14/string-buffer)[ Docs](https://github.com/atk14/StringBuffer)[ RSS](/packages/atk14-string-buffer/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (12)Used By (5)

StringBuffer
============

[](#stringbuffer)

[![Tests](https://github.com/atk14/StringBuffer/actions/workflows/tests.yml/badge.svg)](https://github.com/atk14/StringBuffer/actions/workflows/tests.yml)

StringBuffer is a PHP class providing operations for efficient string buffering. It can hold a mix of plain strings and file contents, and treats them uniformly as a single continuous buffer.

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

[](#installation)

```
composer require atk14/string-buffer

```

Basic usage
-----------

[](#basic-usage)

```
$sb = new StringBuffer();
$sb->addString("Hello World!\n");
$sb->addString(" How are you?");
$sb->addFile("/path/to/file");

$length = $sb->getLength();
$sb->printOut();

```

You can also pass an initial string to the constructor:

```
$sb = new StringBuffer("Hello World!");

```

Combining buffers:

```
$sb1 = new StringBuffer("Hello");
$sb2 = new StringBuffer(" World!");
$sb1->addStringBuffer($sb2);
echo $sb1; // "Hello World!"

```

Converting to string:

```
$string = (string)$sb;
// or
$string = "$sb";
// or
$string = $sb->toString();

```

Other operations:

```
// Replace a substring throughout the buffer
$sb->replace("World", "PHP");

// Extract a portion of the buffer (works like PHP's substr())
$part = $sb->substr(0, 5);
$last = $sb->substr(-3);

// Write the whole buffer to a file
$sb->writeToFile("/path/to/output.dat");

// Clear the buffer
$sb->clear();

```

Memory-efficient temporary buffer
---------------------------------

[](#memory-efficient-temporary-buffer)

`StringBufferTemporary` is a drop-in replacement for `StringBuffer` that automatically offloads content to a temporary file once it exceeds 1 MB. This keeps memory consumption low when working with large amounts of data.

```
$buffer = new StringBufferTemporary();

$buffer->add($megabyte);
$buffer->add($megabyte);
$buffer->add($megabyte);

$buffer->printOut();
// or
$buffer->writeToFile($target_filename);

```

Temporary files are created automatically and deleted when the buffer object is destroyed.

The threshold can be adjusted if needed:

```
StringBufferTemporary::$FILEIZE_THRESHOLD = 512 * 1024; // 512 kB

```

The temporary directory defaults to the system temp dir. To override it, define the `TEMP` constant before using the class:

```
define("TEMP", "/path/to/temp/");

```

Append buffer contents to the file
----------------------------------

[](#append-buffer-contents-to-the-file)

The file opening mode can be passed as the second parameter of the `writeToFile()` method.

```
// Write at the end of the file
$buffer->writeToFile("/path/to/output.dat","a");

```

Licence
-------

[](#licence)

StringBuffer is free software distributed [under the terms of the MIT license](http://www.opensource.org/licenses/mit-license)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance85

Actively maintained with recent releases

Popularity30

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity65

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 ~336 days

Recently: every ~473 days

Total

11

Last Release

78d ago

PHP version history (2 changes)v1.0PHP &gt;=5.3.0

v1.2.5PHP &gt;=5.6.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/974278?v=4)[Jaromir Tomek](/maintainers/yarri)[@yarri](https://github.com/yarri)

---

Top Contributors

[![yarri](https://avatars.githubusercontent.com/u/974278?v=4)](https://github.com/yarri "yarri (52 commits)")

---

Tags

stringstringsBufferbuffering

### Embed Badge

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

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

###  Alternatives

[doctrine/inflector

PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.

11.3k900.4M875](/packages/doctrine-inflector)[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.1k430.4M1.7k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.3M192](/packages/danielstjules-stringy)[kwn/number-to-words

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

4375.4M23](/packages/kwn-number-to-words)[coduo/php-to-string

Simple library that converts PHP value into strings

27013.4M14](/packages/coduo-php-to-string)[opis/string

Multibyte strings as objects

7626.6M9](/packages/opis-string)

PHPackages © 2026

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