从最后一个/之后的 URL 获取值 [英] Get value from URL after the last /

查看:26
本文介绍了从最后一个/之后的 URL 获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经环顾四周,但只能找到在锚标签之后完成的链接和引用,但我需要在最后一个/符号之后获取 URL 的值.

I have looked around for this but can only find links and references to this been done after an anchor hashtag but I need to get the value of the URL after the last / sign.

我见过这样的用法:

www.somesite.com/archive/some-post-or-article/53272

www.somesite.com/archive/some-post-or-article/53272

最后一位 53272 是对会员 ID 的引用..

the last bit 53272 is a reference to an affiliate ID..

先谢谢大家.

推荐答案

PHPs parse_url(从 URL 中提取路径)结合 basename(返回最后一部分)将解决这个问题:

PHPs parse_url (which extracts the path from the URL) combined with basename (which returns the last part) will solve this:

var_dump(basename(parse_url('http://www.somesite.com/archive/some-post-or-article/53272',  PHP_URL_PATH)));
string(5) "53272"

这篇关于从最后一个/之后的 URL 获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆