如何获取url字符串的最后一部分?

时间:2015-04-15 15:44:11

标签: php regex preg-match

我需要从url中提取项目ID,就像这些(最后一次斜杠后面的数字)

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?

1 个答案:

答案 0 :(得分:4)

这应该适合你:

(只需使用basename()

取url(字符串)的最后一部分
echo basename($url);
相关问题