wpseek.com
WordPress开发者和主题制作者的搜索引擎



str_ends_with › WordPress Function

Since5.9.0
已弃用n/a
str_ends_with ( $haystack, $needle )
参数: (2)
  • (string) $haystack The string to search in.
    Required: Yes
  • (string) $needle The substring to search for in the `$haystack`.
    Required: Yes
返回:
  • (bool) True if `$haystack` ends with `$needle`, otherwise false.
定义在:
文档:

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

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


源码

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

		$len = strlen( $needle );

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