What is the easiest way to reference a multibyte string in PHP?

My question is: In PHP it is easy to refer to a single byte string, $single = "abc"; eg,

 echo $single[0]; //"a" 

However, for the multi-byte string $multi = "Γ€Γ₯ΓΆ" I get "nonsense", that is

 echo $multi[0]; //? 

I know that it is possible to refer to individual letters of a multibyte string by encoding as follows:

 mb_internal_encoding("UTF-8"); echo mb_substr($multi,1,1);//which gives the right answer "Γ₯" 

But isn't there an easier way to do this? I am especially looking for a way that I can refer to a string with several bytes with square brackets and only one parameter, as is the case with one byte.

+4
source share
1 answer

Not. Unicode support is in the table for new versions, but it is not ready yet. It will probably come to some extent, but so far.

from the manual :

A string is a series of characters where the character matches a byte. This means that PHP only supports 256-character typing and therefore does not offer native Unicode support.

Closest to this, you can apply the implementation of the ArrayAccess object using the __toString() function and LOT to mess around. Not recommended in my opinion.

+2
source

Source: https://habr.com/ru/post/1394056/


All Articles