php - Access character in a string with square braces doesn't output correctly -


i have string , want access ä character. outputs question mark instead of correct character.

here code.

$array = array('ä', 'b', 'c'); $string = 'äbc'; echo $string; // äbc echo '<br />'; echo $string[0]; // ? echo '<br />'; echo $array[0]; // ä 

demo

can tell me why?

updated

echo strlen($string); // returns 4 echo mb_substr($string, 0, 1); // ä 

depending on charset, letter ä multi-byte letter. when access string using array access, returns first byte. in case of multi-byte ä returns non printable control character.

accessing array using array-access returns first element, regardless of it's length, in case multi-byte ä.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -