wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



str_ends_with › WordPress Function

Depuis5.9.0
Dépréciéen/a
str_ends_with ( $haystack, $needle )
Paramètres: (2)
  • (string) $haystack The string to search in.
    Requis: Oui
  • (string) $needle The substring to search for in the `$haystack`.
    Requis: Oui
Retourne:
  • (bool) True if `$haystack` ends with `$needle`, otherwise false.
Défini(e) dans:
Codex:

Polyfill for `str_ends_with()` function added in PHP 8.0.

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


Source

function str_ends_with( $haystack, $needle ) {
		if ( '' === $haystack ) {
			return '' === $needle;
		}

		$len = strlen( $needle );

		return substr( $haystack, -$len, $len ) === $needle;
	}
}