On 23/06/2021 22:28, Christoph M. Becker wrote:
substr() is about bytes, not characters. They all may have upvoted the
wrong answer. The only correct answer has just 17 upvotes.
Just to out-pedant you, I'll point out that what most people would think
of as a "character" is neither a byte nor a code point, but a grapheme,
so I would say *none* of the answers on that page is correct.
$string = 'Zoë'; // "Zoe\u{0308}" not "Zo\u{00EB}"
var_dump(substr($string, -1));
var_dump(mb_substr($string, -1));
var_dump(grapheme_substr($string, -1));
string(1) "�"
string(2) "̈"
string(3) "ë"
https://3v4l.org/IMoWQ
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php