0

I have example string in UTF-8:

$string = "Nový rok";

Now i tried:

echo $string; // output: Nový rok // CORRECT
echo $string[0] // output: N // CORRECT
echo $string[3] // output: � // INCORRECT

Why $string[3] is incorrect?

I also tried convert string to array by str_split but results is same. Here is code of my test:

<meta charset="utf-8">
<?php
    $string = str_split("Nový rok");
    echo $string[3];
?>

Any idea how to get "ý" from array?

Dave
  • 2,764
  • 2
  • 15
  • 27
  • 4
    Because multi-byte character. Notes statements on the documentation page `str_split() will split into bytes, rather than characters when dealing with a multi-byte encoded string.` – Jonnix Dec 01 '16 at 15:48
  • 1
    Possibly becuase UTF8 does not use 1 byte per char so split them using this - http://stackoverflow.com/questions/3666306/how-to-iterate-utf-8-string-in-php – markdwhite Dec 01 '16 at 15:49
  • @markdwhite thanks for link – Dave Dec 01 '16 at 15:50
  • [What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text](http://kunststube.net/encoding/) – deceze Dec 01 '16 at 15:58

0 Answers0