Get value from URL after the last /

2019-06-14 01:21发布

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.

I have seen this used like this:

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

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

Thanks in advance folks.

标签: php url
9条回答
成全新的幸福
2楼-- · 2019-06-14 01:41
$url = 'www.somesite.com/archive/some-post-or-article/53272';
$parse = explode('/',$url);
$count = count($parse);
$yourValue = $parse[$count-1];

That's all.

查看更多
Ridiculous、
3楼-- · 2019-06-14 01:48
<?php
$url = "www.somesite.com/archive/some-post-or-article/53272";

$last = end(explode("/",$url));

echo $last;

?>

Use this.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-06-14 01:52

You can do this :

$url = 'www.somesite.com/archive/some-post-or-article/53272';
$id = substr(url, strrpos(url, '/') + 1);
查看更多
登录 后发表回答