str_ends_with

函式
str_ends_with ( $haystack, $needle )
引數
  • (string) $haystack The string to search in.
    Required:
  • (string) $needle The substring to search for in the `$haystack`.
    Required:
返回值
  • (bool) True if `$haystack` ends with `$needle`, otherwise false.
定義位置
相關方法
str_starts_withrest_get_date_with_gmtwp_render_widgetkses_initrandom_int
引入
5.9.0
棄用
-

str_ends_with: 這是一個PHP函式,用於檢查一個字串是否以另一個字串結尾。它需要兩個引數,$haystack 和 $needle。如果 $haystack 與 $needle 結尾,則返回 true,否則返回 false。

在 PHP 8.0 中增加了對 `str_ends_with()’函式的填充。

執行區分大小寫的檢查,表明haystack是否以針頭結束。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function str_ends_with( $haystack, $needle ) {
if ( '' === $haystack && '' !== $needle ) {
return false;
}
$len = strlen( $needle );
return 0 === substr_compare( $haystack, $needle, -$len, $len );
}
}
function str_ends_with( $haystack, $needle ) { if ( '' === $haystack && '' !== $needle ) { return false; } $len = strlen( $needle ); return 0 === substr_compare( $haystack, $needle, -$len, $len ); } }
function str_ends_with( $haystack, $needle ) {
		if ( '' === $haystack && '' !== $needle ) {
			return false;
		}

		$len = strlen( $needle );

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

常見問題

FAQs
檢視更多 >