The standard PHP way to test whether a string $str ends with a substring $test is:
$str
$test
$endsWith = substr( $str, -strlen( $test ) ) ==
In PHP 8:
str_ends_with('haystack', 'stack'); // true str_ends_with('haystack', 'K'); // false
and also:
str_starts_with('haystack', 'hay'); // true
PHP RFC: Add str_starts_with(), str_ends_with() and related functions