The str_ends_with
function in PHP checks if a string ends with a certain string.
This function is available in PHP 8 and higher.
str_ends_with(string $haystack, string $needle): bool
The str_ends_with()
function requires two strings as parameters.
This function returns true
if successful and false
if it is not.
<?phpif (str_ends_with('hello', 'lo')) {echo "'hello' end with 'lo'\n";}if (!str_ends_with('hello', 'ol')) {echo "'hello' doesn't end with 'ol'\n";}
'hello' ends with 'lo'
'hello' doesn't end with 'ol'