用JavaScript实现PHP的basename函数

标签: , , , ,

曾经写过一篇《用C语言实现PHP的basename函数》,最近用JavaScript写人人网日志和状态备份工具的时候要用到这个函数,搜索到一个实现。

function basename(path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');
    if (typeof(suffix) == 'string' &&
        b.substr(b.length - suffix.length) == suffix) {
        b = b.substr(0, b.length - suffix.length);
    }
    return b;
}

参考链接:JavaScript basename – php.js

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. 人人网状态及评论导出工具
  2. 用JavaScript实现PHP的urlencode函数
  3. VBS转EXE工具:Exe From Vbs
  4. Scrapy ImportError: DLL load failed: 操作系统无法运行 %1
  5. MySQL中CHAR和VARCHAR的区别

留下回复