The standard PHP way to test whether a string $str ends with a substring $test is:
$str
$test
$endsWith = substr( $str, -strlen( $test ) ) ==
$endsWith = substr_compare( $str, $test, -strlen( $test ) ) === 0
Negative offset "starts counting from the end of the string".