I want to get the first character of a string in PHP. But it returns some unknown character like �
. Why does that happen?
$text = "अच्छी ाqस्थति में"; // Hindi String
$char = $text[0]; // $text{0}; also try here .
echo $char; // output like �
//expected Output अ
//Below code also used
$char = substr($text , 0 , 1); // Getting same output
If I used javascript I found that I get perfect output:
var text = "अच्छी ाqस्थति में"; // Hindi String
var char = text.charAt(0);
console.log(char) // output like अ
Please anyone tell me about that and a solution to this problem? Why these error if charAt
& substr
work the same way?