A PHP internals discussion proposing a new native `grapheme_mask()` function that masks sections of strings by operating on grapheme clusters rather than raw bytes or code points. This enables Unicode-safe masking of sensitive data like credit card numbers, emails, and phone numbers, correctly handling composed characters, diacritical marks, and emoji sequences. The author has a working C prototype based on ICU ubrk and PHPT test cases, and is preparing a formal RFC. A community member also suggests adding a companion `str_mask()` for byte-based masking, which the author agrees to include in the proposal.

โ€ข8m read timeโ€ขFrom externals.io
Post cover image
Table of contents
grapheme_mask("sepehr@example.com ", " ", 2, -12); // result: se ***@ example.comExample with emoji sequences: grapheme_mask("๐Ÿ‘จ๐Ÿฝโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ family", "*", 0, 1); // result: * family
239 Impressions