Reputation: 31
I want to get a single unicode chatacter from a unicode string.
for example:- $str = "पर्वत निर्माणों में कोनसा संचलन कार्य करता है"; echo $str[0];
output is:- �
but i want to get char 'प' at 0 index of the string.
plz help me how to get char 'प' instead of � .
Upvotes: 3
Views: 1834
Reputation: 201588
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);
Upvotes: 6