php url explode

后端 未结 3 1181
逝去的感伤
逝去的感伤 2020-12-20 23:53

I am wanting to grab my product from my url. For example:

http://www.website.com/product-category/iphone

I am wanting to grab the iphone an

3条回答
  •  情书的邮戳
    2020-12-21 00:18

    Just figured it out.This now works with

    $r = $_SERVER['REQUEST_URI']; 
    $r = explode('/', $r);
    $r = array_filter($r);
    $r = array_merge($r, array()); 
    $r = preg_replace('/\?.*/', '', $r);
    
    $endofurl = $r[1];
    echo $endofurl;
    

提交回复
热议问题