substr()
returns the a string made up of the last N
characters, when -N
is passed to it.
"Hello".substr(-2)
=> "lo"
From the docs:
If start is negative, substr uses it as a character index from the end of the string. If start is negative and abs(start) is larger than the length of the string, substr uses 0 as the start index.