美文网首页
截取两个特定字符中间的字符串

截取两个特定字符中间的字符串

作者: charmingcheng | 来源:发表于2017-11-03 10:26 被阅读0次
<?php
$str = "/product/123.html";
$res = getNeedBetween($str,'/','.');
echo $res;

function getNeedBetween($str,$param1,$param2){
    $start  = strripos($str,$param1);//开始字符,查询字符出现在字符串最后一次的位置
    $end    = strripos($str,$param2);//结束字符,查询字符出现在字符串最后一次的位置
    if(($start == false || $end == false) || $start >= $end){
        return 0;
    }
    $res = substr($str,($start+1),($end-$start-1));//字符串截取
    return $res;
}
?>

相关文章

网友评论

      本文标题:截取两个特定字符中间的字符串

      本文链接:https://www.haomeiwen.com/subject/iqazpxtx.html