str_ends_with( string $haystack, string $needle )

Polyfill for str_ends_with() function added in PHP 8.0.


Description

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


Top ↑

Parameters

$haystack

(string) (Required) The string to search in.

$needle

(string) (Required) The substring to search for in the $haystack.


Top ↑

Return

(bool) True if $haystack ends with $needle, otherwise false.


Top ↑

Source

File: wp-includes/compat.php

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

Top ↑

Changelog

Changelog
Version Description
5.9.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.