I'm trying to get a letter out of a word.

$slovo="Привет"; echo $slovo[2]; 

Instead of a letter, a question mark is displayed in a diamond. Encoding costs utf-8 without BOM.

    2 answers 2

    Your Cyrillic version does not work.

    Here is a working version.

     header('Content-Type: text/html; charset=utf-8'); echo substr('Слово', 0, 2); // результат "С" 

    PS The substr() function perceives a Cyrillic letter as 2 characters, therefore, in the example it is 0, 2 , that is, starting from the zero character, print 2 characters (ie, 1 letter).

    • Thank you but no! And for the future, use mb_substr. In this case, you can write like this echo mb_substr ($ slovo, 0, 1); - LEgXr
    • @LEgXr if you advise me what to use, then why did you write non-working code? - mix

    In .htaccess list:

     AddDefaultCharset UTF-8 
    • .htaccess is not, and creating it and adding this line did not help - LEgXr