jfcherng/php-mb-string
High-performance multibyte string class for PHP. Stores text internally as UTF-32 for fast, safe random read/write, replace, insert, and substring operations on long UTF-8 strings—avoiding the repeated decoding overhead of frequent mb_* calls.
Install the package via Composer: composer require jfcherng/php-mb-string. Begin by wrapping long UTF-8 strings in MbString when you need frequent random access or mutation (e.g., new MbString($content)). Start with literal indexing like $str[0] or $str[5] = '許'—these work safely without byte-offset miscalculations. The README’s example and test suite are the first places to look for practical usage.
$mbStr[$i] instead of mb_substr() inside loops—avoiding repeated decoding overhead.MbString as mutable: $str[3] = '你好'; replaces at the 4th codepoint (not byte), enabling safe multi-byte character insertion.$str->replace($from, $to) over str_replace() on raw UTF-8—internally leverages fast index-based operations via UTF-32 conversion.ext-iconv: Ensure it’s enabled—no graceful fallback if missing.$str[0] = first character, not byte—confusing if expecting substr()-style byte offsets.$str[2] = 'x' modify in-place; use clone $str for immutability.MbString with native strings in logic—e.g., comparing $mbStr[0] === $nativeStr[0] may yield false positives due to encoding mismatches.(string)$mbStr or $mbStr->toString() only at final output stages—casting mid-flow adds overhead and defeats performance goals.How can I help you explore Laravel packages today?