可以用 parse_url 这个先解析下,在explode截取下
正则 https://v.qq.com/x/cover/sfwa...
/([\w]+)\.[\w]+$/
正则会比较方便
前几天好像有人问过取URL最后一个/
后到.html
前的部分。。。
https://segmentfault.com/q/10...
basename(end(explode("/",parse_url($url)['path'])),".html")
$path = pathinfo('https://v.qq.com/x/cover/sfwaitvh720feud.html')
echo $path['filename'];//sfwaitvh720feud
可以试试lastIndexOf 这个自带的函数.
var a="https://v.qq.com/x/cover/sfwaitvh720feud.html";
a.substring(a.lastIndexOf('/'),a.lastIndexOf('.'));
打印出来得到
/sfwaitvh720feud
$url = 'https://v.qq.com/x/cover/sfwa...';
$array = explode('.html', $url);
$array_n = explode('/', $array[0]);
$str = end($array_n);
echo $str;