php - 正则截取字符串

 龙晓桥的微博_267 发布于 2022-11-16 12:30

https://v.qq.com/x/cover/sfwaitvh720feud.html截取sfwaitvh720feud这一串。。。

7 个回答
  • $url = 'https://v.qq.com/x/cover/sfwa...';
    $array = explode('.html', $url);
    $array_n = explode('/', $array[0]);
    $str = end($array_n);
    echo $str;

    2022-11-16 13:30 回答
  • 可以试试lastIndexOf 这个自带的函数.

    var a="https://v.qq.com/x/cover/sfwaitvh720feud.html";
    a.substring(a.lastIndexOf('/'),a.lastIndexOf('.'));

    打印出来得到

    /sfwaitvh720feud
    2022-11-16 13:30 回答
  • $path = pathinfo('https://v.qq.com/x/cover/sfwaitvh720feud.html')
    echo $path['filename'];//sfwaitvh720feud
    2022-11-16 13:30 回答
  • basename(end(explode("/",parse_url($url)['path'])),".html")

    2022-11-16 13:30 回答
  • 前几天好像有人问过取URL最后一个/后到.html前的部分。。。
    https://segmentfault.com/q/10...

    2022-11-16 13:30 回答
  • 正则会比较方便

    2022-11-16 13:30 回答
  • 可以用 parse_url 这个先解析下,在explode截取下
    正则 https://v.qq.com/x/cover/sfwa...

      /([\w]+)\.[\w]+$/
    2022-11-16 13:30 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有