How do I get the last part of an url string?

爱⌒轻易说出口 提交于 2019-12-02 21:36:59

问题


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
                                                  //^^^^^^^^

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


回答1:


This should work for you:

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

echo basename($url);


来源:https://stackoverflow.com/questions/29654766/how-do-i-get-the-last-part-of-an-url-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!