Answers for "how to use startswith and endswith to filter in php"

PHP
3

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);
}
Posted by: Guest on May-18-2020

Code answers related to "how to use startswith and endswith to filter in php"

Browse Popular Code Answers by Language