如何从php中的unicode字符串中获取unicode字符 [英] how to get unicode character from a unicode string in php
问题描述
我想从unicode字符串中获得一个unicode聊天对象.
I want to get a single unicode chatacter from a unicode string.
例如:- $ str =पर्वािोोो"; echo $ str [0];
for example:- $str = "पर्वत निर्माणों में कोनसा संचलन कार्य करता है"; echo $str[0];
输出为:-
但是我想在字符串的0索引处获取char'प'.
but i want to get char 'प' at 0 index of the string.
plz帮助我如何获取char'प'而不是 .
plz help me how to get char 'प' instead of � .
推荐答案
正如@deceze所写,您需要使用 mb_substr
以获得字符,而不只是一个字节.另外,您需要使用 mb_internal_encoding 设置内部编码.假设您的.php文件的编码为UTF-8,则应该可以进行以下操作:
As @deceze writes, you need to use mb_substr
in order to get a character, instead of just a byte. In addition, you need to set the internal encoding with mb_internal_encoding. Assuming that the encoding of your .php file is UTF-8, the following should work:
mb_internal_encoding('utf-8');
$str = "पर्वत निर्माणों में कोनसा संचलन कार्य करता है";
echo mb_substr($str, 0, 1);
这篇关于如何从php中的unicode字符串中获取unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!