How to Get the Last Character in a String with PHP
There a number of ways to get the last character in a string by using PHP. The simplest way I find however is to use the substr() function like so:
- $str = "This is a string";
- echo substr($str, -1);
The above example would return ‘g’. By passing a negative value as the second parameter we can tell PHP to start at the nth character from the end.
0 comments:
Post a Comment