📜  PHP 代码示例中的 startsWith() 和 endsWith() 函数

📅  最后修改于: 2022-03-11 14:53:45.706000             🧑  作者: Mango

代码示例2
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);
}