实现php的startsWith和endsWith

Posted 一菲聪天

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现php的startsWith和endsWith相关的知识,希望对你有一定的参考价值。

startsWith():

function startsWith($haystack, $needle){
    return strncmp($haystack, $needle, strlen($needle)) === 0;
}

 

endsWith():

function endsWith($haystack, $needle){
    return $needle === ‘‘ || substr_compare($haystack, $needle, -strlen($needle)) === 0;
}

 

参考:https://www.gowhich.com/blog/747
           https://leonax.net/p/7804/string-startswith-and-endswith-in-php/


以上是关于实现php的startsWith和endsWith的主要内容,如果未能解决你的问题,请参考以下文章