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

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

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -