CodyKochmann
5/9/2017 - 6:28 PM

find if a string starts with or ends with a substring in php From https://stackoverflow.com/questions/834303/startswith-and-endswith-functio

find if a string starts with or ends with a substring in php From https://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php

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);
}