返回URL的特定部分(return specific part of URL)
我希望通过php返回URL的特定部分。 例如,如果URL是:
http://website.com/part1/part2/part3/detail/page_id/number/page/2要么
http://website.com/part1/part2/part3/detail/page_id/number/page/3我想要退货号码。
好吗?
$pattern = "/\d+$/"; $input = "http://website.com/part1/part2/part3/detail/page_id/number/page/2"; preg_match($pattern, $input, $matches); $post_id = $matches[8];I want return specific part of URL by php. for example if URL is :
http://website.com/part1/part2/part3/detail/page_id/number/page/2or
http://website.com/part1/part2/part3/detail/page_id/number/page/3I want return number.
is it okay?
$pattern = "/\d+$/"; $input = "http://website.com/part1/part2/part3/detail/page_id/number/page/2"; preg_match($pattern, $input, $matches); $post_id = $matches[8];最满意答案
我认为id会在$matches[0] 。 但是这个正则表达式模式会匹配最后一个数字的任何url。 例如
http://differentdomain.com/whatever/7也许这对你来说已经足够了,如果没有,请更详细地描述你的用例。
use it:
return $id3 = $parts[count($parts) - 3];
更多推荐
发布评论