Skip to content

Instantly share code, notes, and snippets.

@Pleiades
Created May 5, 2019 00:05
Show Gist options
  • Save Pleiades/d80fb6dcf308eedcca71008ec5bbe324 to your computer and use it in GitHub Desktop.
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
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