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

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);
 }

 

 
posted on 2015-10-22 12:53  清清飞扬  阅读(9129)  评论(1编辑  收藏  举报