The str_ends_with
function in PHP is used to check if a string ends with a certain string.
Note: This function is only available in PHP 8 onwards.
str_ends_with(string $haystack, string $needle): bool
haystack
: the string where we want to searchneedle
: the string we will search forThe function returns true
if the given string ends with the given needle. Otherwise, it returns false
.
In this example, we will check our string ends with Educative!
:
<?phpvar_dump(str_ends_with("Hello, Educative!", "Educative!"));?>
bool(true)