PHP can pad a string by bytes with str_pad() and by code points with mb_str_pad(). It can't pad by what a reader sees as one character. Chris Abner Herrera Navarro's RFC adds grapheme_str_pad() to ext/intl to fill that gap.

A grapheme cluster is one visible character, even when it's built from several code points. An accented letter typed as e plus a combining accent, a Japanese kana with a combining mark, or a thumbs-up emoji with a skin tone are each one cluster. The grapheme_* functions count in this unit, and the mb_str_pad RFC already listed a grapheme version as future work.

Show me

The same word "Café" can be stored two ways. mb_str_pad() pads them differently, while grapheme_str_pad() gives both the same padding:

$nfc = "Caf\u{00E9}";    // "Café", é as one code point
$nfd = "Cafe\u{0301}";   // "Café", e followed by a combining acute accent

mb_str_pad($nfc, 6, '.');       // "Café.."
mb_str_pad($nfd, 6, '.');       // "Café."   one dot less

grapheme_str_pad($nfc, 6, '.'); // "Café.."
grapheme_str_pad($nfd, 6, '.'); // "Café.."

Emoji work the same way. mb_str_pad("👍🏽", 3, '-', STR_PAD_LEFT) adds one dash, because the emoji counts as two code points. grapheme_str_pad() adds two.

How it works

The signature matches mb_str_pad():

function grapheme_str_pad(string $string, int $length, string $pad_string = " ", int $pad_type = STR_PAD_RIGHT): string|false {}

$length is counted in grapheme clusters, the way grapheme_strlen() counts them. The rest follows str_pad():

  • If $length isn't longer than the string, you get the string back unchanged.
  • STR_PAD_LEFT, STR_PAD_RIGHT and STR_PAD_BOTH work as before. With STR_PAD_BOTH, any odd cluster goes on the right.
  • When the last copy of the padding string doesn't fit, it's cut between clusters, never inside one. mb_str_pad() can cut an accent off a padding character.
  • For plain ASCII the result is the same as str_pad().

When padding is needed, an empty padding string or an unknown pad type throws a ValueError, as in mb_str_pad(), and invalid UTF-8 returns false and sets the intl error. When no padding is needed, you get the string back without those checks on the padding string.

Today you'd write this yourself with grapheme_strlen() and grapheme_substr(). Symfony's String component already does that in UnicodeString::padStart(), padEnd() and padBoth().

What it means for existing code

Nothing changes. It's a new function in ext/intl, and only a userland function with the same name would clash. The author found none on GitHub or Sourcegraph.

Where it stands

Chris Abner Herrera Navarro opened the internals discussion on November 3, 2026, targeting PHP 8.7. Pull request #25179 has the implementation and tests. Acceptance needs a two-thirds majority. No vote has been scheduled yet.