Created
May 5, 2019 00:05
-
-
Save Pleiades/d80fb6dcf308eedcca71008ec5bbe324 to your computer and use it in GitHub Desktop.
Take a string and return if it starts with the specified character/string or ends with it
This file contains 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
function startsWith($haystack, $needle) | |
{ | |
$length = strlen($needle); | |
return (substr($haystack, 0, $length) === $needle); | |
} | |
function endsWith($haystack, $needle) | |
{ | |
$length = strlen($needle); | |
if ($length == 0) { | |
return true; | |
} | |
return (substr($haystack, -$length) === $needle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment