Last active
May 3, 2021 21:34
-
-
Save garethflowers/31e97bcb1679008fc064 to your computer and use it in GitHub Desktop.
Finds whether a string ends with another string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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