Re: Introduce str_left/right In 8.1

From: Date: Thu, 24 Jun 2021 07:56:05 +0000
Subject: Re: Introduce str_left/right In 8.1
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-115098@lists.php.net to get a copy of this message
On Wed, Jun 23, 2021 at 11:54 PM Rowan Tommins <rowan.collins@gmail.com> wrote: > 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 > I thought about the same during the night! Just to complete: there's also iconv_substr() (but with the same result as mb_substr()), and here are two links to compare: https://3v4l.org/kU9D5 vs https://3v4l.org/pAvB0 Regards, -- Guilliam Xavier

« previous php.internals (#115098) next »