There is a string "abc".

How on php by means of substr I get the second letter?

I write: substr('abc', 0, 2) , but does not help.

What am I doing wrong?

    1 answer 1

    The second letter is the letter number 1, since considered from scratch. If you need one letter. then the length = 1.

     substr('abc', 1, 1) 

    But if a string is a variable, not a literal, then it is also possible by index:

     $a = 'abc'; $second_letter = $a[1]; 
    • 2
      Just do not forget, IT does not work with uttf-8 and you need to use mb_* functions. - And