Checks if a string is ends with a given substring.
Use strrpos()
in combination with strlen
to find the position of $needle
in $haystack
.
代码实现
function endsWith($haystack, $needle)
{
return strrpos($haystack, $needle) === (strlen($haystack) - strlen($needle));
}
使用样例
endsWith('Hi, this is me', 'me'); // true