From what I have been able to test, the subtr () function does not work with negative offset, I mean the start and length values from the end of the string. Examples:
$rest = substr(“abcdef”, -1); // returns “f”
$rest = substr(“abcdef”, -2); // returns “ef”
$rest = substr(“abcdef”, -3, 1); // returns “d”
A specific excerpt that is relevant to you:
If either or both of the arguments are negative or
NaN , the
substring() method treats them as if they were
console.log(text.substring(-5, 2)) // => "Mo"
console.log(text.substring(-5, -2)) // => ""
I am using a workaround as it is deprecated:
substr( string, stringlenght(string) -number, number)