Checks if a string ends with a given substring
Syntax
str_ends_with ( string $haystack , string $needle ) : bool
Parameters
haystack
The string to search in.
needle
The substring to search for in the haystack.
Return
Returns TRUE if haystack ends with needle, FALSE otherwise.
Examples
1
<? $haystack = "haystack haystack needle"; $needle = "needle"; $return = str_ends_with($haystack, $needle); var_export($return); ?>
true
2
<? $haystack = "haystack"; $needle = "needle"; $return = str_ends_with($haystack, $needle); var_export($return); ?>
false
3
<? $haystack = "empty needle returns true"; $needle = ""; $return = str_ends_with($haystack, $needle); var_export($return); ?>
true
4
<? $haystack = "case Case CASE"; $needle1 = "case"; $needle2 = "Case"; $needle3 = "CASE"; $return1 = str_ends_with($haystack, $needle1); $return2 = str_ends_with($haystack, $needle2); $return3 = str_ends_with($haystack, $needle3); var_export($return1); var_export($return2); var_export($return3); ?>
falsefalsetrue