php 字符串 以 开头 以结尾 startWith endWith

时间:2015-10-22 14:09:05   收藏:0   阅读:3253

From: http://www.shipingzhong.cn/node/1217

//第一个是原串,第二个是 部份串
function startWith($str, $needle) {

    return strpos($str, $needle) === 0;

}

//第一个是原串,第二个是 部份串
 function endWith($haystack, $needle) {   

      $length = strlen($needle);  
      if($length == 0)
      {    
          return true;  
      }  
      return (substr($haystack, -$length) === $needle);
 }

 

 
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!