# RFC karma request: grapheme_str_pad()

- Thread: https://externals.io/message/132967
- Original archive: https://news-web.php.net/php.internals/132967
- Started by Chris Abner Herrera Navarro on 2026-10-29T22:00:35+00:00
- Messages: 1
- RFC: mb_str_pad (Implemented (PHP 8.3)) — https://externals.io/rfc/mb_str_pad.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #132967 — Chris Abner Herrera Navarro — 2026-10-29T22:00:35+00:00

URL: https://externals.io/message/132967#132967

Hi internals,

I'd like to request RFC karma on the wiki to propose a new function,
grapheme_str_pad(). My wiki username is: chrisabner

It is the grapheme cluster counterpart of `str_pad()` and `mb_str_pad()`, as
suggested in the Future Scope of the mb_str_pad RFC [1]. The length is
counted in grapheme clusters, like `grapheme_strlen()` does:

    grapheme_str_pad(string $string, int $length, string $pad_string = " ",
                     int $pad_type = STR_PAD_RIGHT): string|false
 `mb_str_pad()` counts code points, so the same visible text gets different
padding depending on how it is encoded, and the padding string can be cut
inside a grapheme cluster:

    mb_str_pad("Caf\u{00E9}", 6, '.');           // "Café.."
    mb_str_pad("Cafe\u{0301}", 6, '.');          // "Café."  (NFD: one dot less)
    mb_str_pad("a", 4, "u\u{0308}o\u{0308}");    // "aüo"    (ö lost its diaeresis)

    grapheme_str_pad("Cafe\u{0301}", 6, '.');       // "Café.."
    grapheme_str_pad("a", 4, "u\u{0308}o\u{0308}"); // "aüöü"

Errors and edge cases follow `mb_str_pad()`; invalid UTF-8 returns false like `grapheme_strlen()`. I have an implementation with tests in ext/intl and will
open a pull request together with the RFC.

I'll open the formal [RFC] discussion thread once the wiki page is up.

[1] https://wiki.php.net/rfc/mb_str_pad#future_scope

Thanks,
Chris Abner Herrera Navarro
