str_ends_with()WP 5.9.0

Performs a case-sensitive check indicating if the haystack ends with needle.

No Hooks.

Return

true|false. True if $haystack ends with $needle, otherwise false.

Usage

str_ends_with( $haystack, $needle );
$haystack(string) (required)
The string to search in.
$needle(string) (required)
The substring to search for in the $haystack.

Changelog

Since 5.9.0 Introduced.

Code of str_ends_with() WP 6.0

function str_ends_with( $haystack, $needle ) {
	if ( '' === $haystack && '' !== $needle ) {
		return false;
	}
	$len = strlen( $needle );
	return 0 === substr_compare( $haystack, $needle, -$len, $len );
}