In this tutorial will help you for getting last 4 characters of a string in PHP language.
We used substr function for gettting four chars or any length.
You may also like: How to get the last character of a string in PHP (with multi byte chars)
Substr, Returns the portion of string
specified by the offset
and length
parameters.
Here our example:
1 2 3 4 5 6 7 8 9 10 11 12 | <?php $str = "Code4Example"; $len = 4; //get last 4 chars $result = substr($str, strlen($str)-$len); echo $result; ?> |
Output:
1 2 3 | mple |