码迷,mamicode.com
首页 > Web开发 > 详细

实现php的startsWith和endsWith

时间:2018-07-24 00:45:09      阅读:505      评论:0      收藏:0      [点我收藏+]

标签:stack   ret   function   ===   cti   style   compare   fun   tac   

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

标签:stack   ret   function   ===   cti   style   compare   fun   tac   

原文地址:https://www.cnblogs.com/tommy-huang/p/9357631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!