A PHP internals discussion proposing a new native function `grapheme_mask()` to handle masking of sensitive string sections (credit card numbers, emails, phone numbers) in a Unicode-safe way. Current approaches using `substr()`, `strlen()`, `str_repeat()`, and `substr_replace()` are repetitive and error-prone, especially with Unicode edge cases. The proposed function operates on grapheme clusters rather than raw bytes or code points, correctly handling composed characters and emoji sequences. The author is gauging community interest before drafting a formal RFC.

โ€ข2m 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
85 Impressions