Home Menu

str_ends_with

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 = "an empty needle returns true";
$needle = "";

$return = str_ends_with($haystack, $needle);

var_export($return);

?>
true

3

<?

$haystack = "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);

?>
falsetruefalse

Internal

str_contains

str_starts_with

External

PHP

JesusBible
HTMLCSSJSPHPSVGMore
AboutTerms