简体   繁体   English

如何获得网址字符串的最后一部分?

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

I need extract item id from url's like these (number after last slash) 我需要像这样从网址中提取项目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
                                                  //^^^^^^^^

Some items has digits in name. 有些项目的名称中有数字。 How i can extract just id at end of links with regular expression in php? 我如何在PHP中使用正则表达式链接的末尾提取ID?

This should work for you: 这应该为您工作:

(Just take the last part of the url (string) with basename() ) (只需使用basename()取url(字符串)的最后一部分)

echo basename($url);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM