In this tutorial learn how to Check if a string ends with a substring in php using stripos() and strlen() methods.
TUTORIAL
function str_ends_with(string $string, string $substr): bool
{
return stripos($string, $substr) === strlen($string) - strlen($substr);
}
TUTORIAL
<?php
/**
* Check if a string ends with a substring
*
* @param string $string
* @param string $substr
* @return bool
*/
function str_ends_with(string $string, string $substr): bool
{
return stripos($string, $substr) === strlen($string) - strlen($substr);
}
var_dump( str_ends_with("This is test!", "test!"));
OUTPUT DEMObool(true)
No comments:
Post a Comment