PHPackages                             jfcherng/php-mb-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. jfcherng/php-mb-string

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

jfcherng/php-mb-string
======================

A high performance multibytes sting implementation for frequently reading/writing operations.

2.0.1(3y ago)145.1M—0.8%[1 PRs](https://github.com/jfcherng/php-mb-string/pulls)1MITPHPPHP &gt;=8.1

Since Jun 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jfcherng/php-mb-string)[ Packagist](https://packagist.org/packages/jfcherng/php-mb-string)[ Fund](https://www.paypal.me/jfcherng/5usd)[ RSS](/packages/jfcherng-php-mb-string/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (24)Used By (1)

php-mb-string
=============

[](#php-mb-string)

[![GitHub Workflow Status (branch)](https://camo.githubusercontent.com/edbf9d99772a6d978dec79c7295b39526f9c739aeffc46747a42b9003e7b000c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a66636865726e672f7068702d6d622d737472696e672f7068702e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/jfcherng/php-mb-string/actions)[![Packagist](https://camo.githubusercontent.com/bb2936e21249f1d874f427978bc5604e13794af24a1eca44f46921e660ed5685/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a66636865726e672f7068702d6d622d737472696e673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jfcherng/php-mb-string)[![Packagist Version](https://camo.githubusercontent.com/8f88a32f60f1ee8f36402bf5f802b463a6040106af7d13e71633455940460cc9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a66636865726e672f7068702d6d622d737472696e673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jfcherng/php-mb-string)[![Project license](https://camo.githubusercontent.com/fc93d7f245d419ee3b1edabf78752af9a130f8301894f958f2c2dde7bcb3688b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a66636865726e672f7068702d6d622d737472696e673f7374796c653d666c61742d737175617265)](https://github.com/jfcherng/php-mb-string/blob/master/LICENSE)[![GitHub stars](https://camo.githubusercontent.com/6dea0907b4333e29464c6f49f62bbc11a74b197bb8d72cb2f6e03c8e910c6508/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6a66636865726e672f7068702d6d622d737472696e673f7374796c653d666c61742d737175617265266c6f676f3d676974687562)](https://github.com/jfcherng/php-mb-string/stargazers)[![Donate to this project using Paypal](https://camo.githubusercontent.com/b3f28a26023aadc92afb98cdbcec5f66ed5b471222cf2af28454b871d93372f4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d646f6e6174652d626c75652e7376673f7374796c653d666c61742d737175617265266c6f676f3d70617970616c)](https://www.paypal.me/jfcherng/5usd)

A high performance multibyte sting implementation for frequently reading/writing operations.

Why I Write This Package?
-------------------------

[](#why-i-write-this-package)

Consider that you have a **LONG** multibyte string and you want to do lots of following operations on it.

- Random reading/writing such as `$char = $str[5];` or `$str[5] = '許';`.
- Replacement such as `str_replace($search, $replace, $str);`.
- Insertion such as `substr_replace($insert, $str, $position, 0);`.
- Get substring such as `substr($str, $start, $length);`.

Because strings in PHP are not UTF-8, to do operations above safely, you have to either use `mb_*()` functions or calculate the index by yourself. Using `mb_*()` functions frequently can be a performance loss because it has to re-decode the source string basing on the given encoding every time when you call it. The longer the string is, the severer the problem becomes.

Instead, this class internally stores the string in its UTF-32 form, which is fixed-width (1 char always occupies 4 bytes) so we are able to perform speedy random accesses. With the power of random access, we could use `str_*()` functions to do the job internally.

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

[](#installation)

```
composer require jfcherng/php-mb-string
```

Example
-------

[](#example)

See [tests/MbStringTest.php](https://github.com/jfcherng/php-mb-string/blob/master/tests/MbStringTest.php).

Benchmark
---------

[](#benchmark)

See [benchmark/\_results.txt](https://github.com/jfcherng/php-mb-string/blob/master/benchmark/_results.txt).

What Are You Doing With This Package?
-------------------------------------

[](#what-are-you-doing-with-this-package)

I develop this for a PHP diff package, [jfcherng/php-diff](https://github.com/jfcherng/php-diff).

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity50

Moderate usage in the ecosystem

Community9

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

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

Recently: every ~12 days

Total

22

Last Release

1127d ago

Major Versions

1.4.7 → 2.0.02023-02-26

v1.x-dev → 2.0.12023-04-17

PHP version history (3 changes)1.0.0PHP ^7.1.3

1.4.2PHP &gt;=7.1.3

2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/8bc4125874806870871f4d302012bc3686498a362eb6c8b70a202af79cf72d5f?d=identicon)[jfcherng](/maintainers/jfcherng)

---

Top Contributors

[![jfcherng](https://avatars.githubusercontent.com/u/6594915?v=4)](https://github.com/jfcherng "jfcherng (97 commits)")

---

Tags

mbstringmultibyte-stringsphp-71psr-1psr-2psr-4stringutf-32utf-8

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/jfcherng-php-mb-string/health.svg)

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

PHPackages © 2026

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