如何在PHP中获取字符串的最后一个字符? [英] How to get the last char of a string in PHP?

查看:2259
本文介绍了如何在PHP中获取字符串的最后一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取字符串的最后一个字符. 假设我有测试人员"作为输入字符串,并且我希望结果为"s".如何在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"

或者,对于多字节字符串:

Or, for multibytes strings :

substr("multibyte string…", -1); // returns "…"

这篇关于如何在PHP中获取字符串的最后一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆