php如何截取字符串中/倒数第2次出现到字符串结尾的内容?

比如
https://domain/a/b.htm
截取
/a/b.htm

https://domain/a/b/c.htm
截取
/b/c.htm

如果着重倒数第二个/之后的内容,思路有很多。

<?php

//思路先截取倒数第一/之后的内容,再加上倒数第一个/和倒数第二个/中间的内容
$str="https://domain/a/b.htm";

$arr = explode("/",$str);
$second = $arr[count($arr)-2]; //截取倒数第一个/和第二个/中间的内容


$url_array = explode("/", $str);  //截取倒数第一个/之后的内容
$last= $url_array[4];


print("/");
print($second);
print("/");
print($last);


######################################################
<?php
$str='https://domain/a/b.htm';
//从第14的位置开始,截取8个长度的字符串。
echo substr($str,14,8);

img