jfcherng/php-mb-string 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jfcherng/php-mb-string

最新稳定版本:2.0.1

Composer 安装命令:

composer require jfcherng/php-mb-string

包简介

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

README 文档

README

GitHub Workflow Status (branch) Packagist Packagist Version Project license GitHub stars Donate to this project using Paypal

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

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

composer require jfcherng/php-mb-string

Example

See tests/MbStringTest.php.

Benchmark

See benchmark/_results.txt.

What Are You Doing With This Package?

I develop this for a PHP diff package, jfcherng/php-diff.

统计信息

  • 总下载量: 4.59M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04