📜  php 字符串以 - PHP 代码示例结尾

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

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