Re: [Discussion] Introducing str_mask() for partial string masking
| From: | Rowan Tommins [IMSoP] | Date: | Thu, 18 Jun 2026 16:26:29 +0000 |
| Subject: | Re: [Discussion] Introducing str_mask() for partial string masking | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-131384@lists.php.net to get a copy of this message | ||
On 18 June 2026 17:13:59 BST, "سپهر محمودی" <sepehrphpr@gmail.com> wrote:
>Hi everyone,
>
>I would like to propose a new native utility function: str_mask().
I can definitely see the use case for this function - in fact, I was just reviewing a change which
could have used it.
>Multibyte Support: Unlike custom userland implementations that might
>break on non-Latin strings (like Persian/Arabic/CJK), a native
>implementation can seamlessly handle multibyte characters.
As a rule, PHP's str_* functions operate on byte strings with no knowledge of encoding.
Multibyte support would belong in the mbstring or intl extensions, which have conventions for
specifying the encoding in use.
In fact, a correct Unicode implementation would need to operate on "graphemes", using the
bindings to ICU in the intl extension. Otherwise, it would incorrectly handle things like combining
diacritics and emoji variation selectors.
Rowan Tommins
[IMSoP]