我想从php中的URL获取id值这是SEO URL
http://www.travelhome.co.in/domestic-tour-itinerary/54/amarnath-yatra-by-road-pahalgam
我希望获得54 in $ id $id=54
我已经尝试了
$uri = $_SERVER["REQUEST_URI"];
$uriArray = explode('/', $uri);
$link = $urlArray[1];
$id = $urlArray[2];
答案 0 :(得分:0)
检查此代码:
$str = $_SERVER["REQUEST_URI"];
preg_match_all('!\d+!', $str, $matches);
print_r($matches);
答案 1 :(得分:0)
$uri = $_SERVER["REQUEST_URI"];
$uriArray = explode('/', $uri);
$link = $uriArray[1];
$id = $uriArray[2];
和.htaccess
RewriteBase /
RewriteRule ^domestic-tour-itinerary/(.*)/(.*)$ domestic-tour-itinerary/?id=$1&title=$2 [L,NC]
我从网址
获得了$ id = 54