Skip to content

Instantly share code, notes, and snippets.

@garethflowers
Last active May 3, 2021 21:34
Show Gist options
  • Select an option

  • Save garethflowers/31e97bcb1679008fc064 to your computer and use it in GitHub Desktop.

Select an option

Save garethflowers/31e97bcb1679008fc064 to your computer and use it in GitHub Desktop.
Finds whether a string ends with another string.
/**
* Finds whether a string ends with another string
*
* @param string $haystack
* @param string $needle
* @return boolean
*/
function str_endswith($haystack, $needle) {
$strlen = strlen($haystack);
$testlen = strlen($needle);
if ($testlen > $strlen) {
return false;
}
return substr_compare($haystack, $needle, -$testlen) === 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment