Easy but not for all of us to get last character from string in PHP. It ‘s quite simple to figure out with a quick Google it. So if you found my article about this. Then you are in right place to solve this issuse with a simplest way.
1. Get the last char of a string in PHP
If you want to get the only one character in a string, here is simplest function to do.
1 | substr("testers", -1); // returns "s" |
So simple?
And what if you want 2 characters? Let ‘s do this
1 | substr("testers", -2); // returns "rs" |
2. Remove the last character from string
Just a bonus if this article, if you want to remove the last character in a string. You can do this function
1 | substr("a,b,c,d,e,", 0, -1); |
The output is a,b,c,d,e
Hope this article help you solve the problem with string.
Thanks