rfc:grapheme_mask

PHP RFC: Grapheme Mask

* Version: 1.0 * Date: 2026-06-25 * Author: Sepehr, sepehrphpr@gmail.com * Status: Draft * First Published at: http://wiki.php.net/rfc/grapheme_mask * Implementation: TBD * Discussion thread: https://news-web.php.net/php.internals/

Introduction

This RFC proposes a new function grapheme_mask() to the Intl extension. This function allows masking a string with a specific character while being “Unicode-aware” by respecting grapheme cluster boundaries.

Proposal

Add the following function:

function grapheme_mask(string $string, string $mask_char = "*", int $start = 0, ?int $length = null): string|false {}

The function will correctly identify individual graphemes (like emojis or combined characters) and replace them with the $mask_char, ensuring the visual integrity of the string is maintained.

Examples

// Traditional str_repeat/masking might break emojis
echo grapheme_mask("سلام 👋", "#"); 
// Output: ##### (Correctly identifies 5 graphemes)

Proposed PHP Version(s)

PHP 8.4 or 8.5 (Next minor version).

Proposed Changes

The implementation will be part of the ext/intl extension, utilizing the ICU library's break iterator.

Vote

TBD

rfc/grapheme_mask.txt · Last modified: by sepehrphp