how to get the last char of a string in PHP?

I need to get the last character of a string. Say I have "testers" as input string and I want the result to be "s". how can I do that in PHP?


substr("testers", -1); // returns "s"

substr($string, -1) 

Or by direct string access:

$string[strlen($string)-1];

Note that this doesn't work for multibyte strings. If you need to work with multibyte string, consider using the mb_* string family of functions.

链接地址: http://www.djcxy.com/p/58192.html

上一篇: 获取字符串的前n个字符

下一篇: 如何获取PHP中的字符串的最后一个字符?