Skip to content
PHP News
Search
Implemented PHP 8.6

grapheme_strrev: strrev for grapheme cluster

Adds grapheme_strrev() to intl, which reverses a string by grapheme cluster so emoji and combined characters stay intact.

Add grapheme_strrev function

Primary vote · 2/3 majority

20 Yes 0 No 100% approval

This poll has closed.

Accepted. Voting closed on February 20, 2026 with 20 in favor, none against and no abstentions, clearing the two-thirds majority it needed. It ships in PHP 8.6.

Summary

strrev() reverses a string byte by byte, which breaks any character that takes more than one byte. Some people write their own mb_strrev() that works one code point at a time, but that still breaks emoji built from several code points, like a family emoji. This RFC from Yuya Hamada adds grapheme_strrev() to the intl extension, which reverses a string by grapheme cluster. A grapheme cluster is what you see on screen as a single character, even when it's made of several code points.

Show me

echo grapheme_strrev("ฮฑใ‚ใ„ใ†ใˆใŠ๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"); // result is "๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆใŠใˆใ†ใ„ใ‚ฮฑ"

The family emoji stays in one piece and just moves to the front. The RFC says it handles right-to-left languages like Arabic, too.

The author compares it to Swift's String.reversed(), which behaves almost the same way.

What it means for existing code

The only risk is a name clash. If your code already defines its own grapheme_strrev() function, it will conflict with the new one. Nothing else changes.