如何获取 url 字符串的最后一部分? [英] How do I get the last part of an url string?

查看:55
本文介绍了如何获取 url 字符串的最后一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要像这样从 url 中提取项目 ID(最后一个斜杠后的数字)

I need extract item id from url's like these (number after last slash)

http://codecanyon.net/item/test item/12219820
                                   //^^^^^^^^
http://codecanyon.net/item/another item/75219586
                                      //^^^^^^^^
http://codecanyon.net/item/item contain number v1.2/74419586
                                                  //^^^^^^^^

有些项目的名称中有数字.我如何在php中使用正则表达式在链接末尾提取id?

Some items has digits in name. How i can extract just id at end of links with regular expression in php?

推荐答案

这应该适合你:

(只需使用 basename())

(Just take the last part of the url (string) with basename())

echo basename($url);

这篇关于如何获取 url 字符串的最后一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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