`

php startsWith,endsWith

    博客分类:
  • php
PHP 
阅读更多

php并没有内置startsWith,endsWith这两个函数,以下是一个实现

 

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

function endsWith($haystack, $needle) {
    $length = strlen($needle);
 $start =  $length *-1; //negative
 return (substr($haystack, $start, $length) === $needle);
}

2
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics