Debian Codegraph @

vendor/jfcherng/php-mb-string/README.md

raw
1 # php-mb-string
2
3 [![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/jfcherng/php-mb-string/php.yml?branch=master&style=flat-square)](https://github.com/jfcherng/php-mb-string/actions)
4 [![Packagist](https://img.shields.io/packagist/dt/jfcherng/php-mb-string?style=flat-square)](https://packagist.org/packages/jfcherng/php-mb-string)
5 [![Packagist Version](https://img.shields.io/packagist/v/jfcherng/php-mb-string?style=flat-square)](https://packagist.org/packages/jfcherng/php-mb-string)
6 [![Project license](https://img.shields.io/github/license/jfcherng/php-mb-string?style=flat-square)](https://github.com/jfcherng/php-mb-string/blob/master/LICENSE)
7 [![GitHub stars](https://img.shields.io/github/stars/jfcherng/php-mb-string?style=flat-square&logo=github)](https://github.com/jfcherng/php-mb-string/stargazers)
8 [![Donate to this project using Paypal](https://img.shields.io/badge/paypal-donate-blue.svg?style=flat-square&logo=paypal)](https://www.paypal.me/jfcherng/5usd)
9
10 A high performance multibyte sting implementation for frequently reading/writing operations.
11
12 ## Why I Write This Package?
13
14 Consider that you have a **LONG** multibyte string and
15 you want to do lots of following operations on it.
16
17 - Random reading/writing such as `$char = $str[5];` or `$str[5] = '許';`.
18 - Replacement such as `str_replace($search, $replace, $str);`.
19 - Insertion such as `substr_replace($insert, $str, $position, 0);`.
20 - Get substring such as `substr($str, $start, $length);`.
21
22 Because strings in PHP are not UTF-8, to do operations above safely,
23 you have to either use `mb_*()` functions or calculate the index by yourself.
24 Using `mb_*()` functions frequently can be a performance loss because it has
25 to re-decode the source string basing on the given encoding every time when you call it.
26 The longer the string is, the severer the problem becomes.
27
28 Instead, this class internally stores the string in its UTF-32 form,
29 which is fixed-width (1 char always occupies 4 bytes) so we are able to
30 perform speedy random accesses. With the power of random access, we could
31 use `str_*()` functions to do the job internally.
32
33 ## Installation
34
35 ```bash
36 composer require jfcherng/php-mb-string
37 ```
38
39 ## Example
40
41 See [tests/MbStringTest.php](https://github.com/jfcherng/php-mb-string/blob/master/tests/MbStringTest.php).
42
43 ## Benchmark
44
45 See [benchmark/\_results.txt](https://github.com/jfcherng/php-mb-string/blob/master/benchmark/_results.txt).
46
47 ## What Are You Doing With This Package?
48
49 I develop this for a PHP diff package, [jfcherng/php-diff](https://github.com/jfcherng/php-diff).