how to get unicode character from a unicode string in php

前端 未结 2 1606
面向向阳花
面向向阳花 2020-12-21 07:30

I want to get a single unicode chatacter from a unicode string.

for example:- $str = \"पर्वत निर्माणों में कोनसा संचलन कार्य करता है\"; echo $str[0];

outpu

2条回答
  •  温柔的废话
    2020-12-21 08:08

    PHP's default $str[x] notation operates on bytes, so you're just getting the first part of a multibyte character. To extract entire encoding aware byte sequences for whole characters, you need to use mb_substr.

    Also see What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text.

提交回复
热议问题