php url explode

后端 未结 3 1180
逝去的感伤
逝去的感伤 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:32

    If you want to retrieve the last element of the array, you can use the end function. The rest of your code seems to be working.

    $endofurl = end($r);
    

    You could also leverage parse_url and strrchr functions to make it more concise:

    $endofurl = strrchr(parse_url($url, PHP_URL_PATH), '/');
    

提交回复
热议问题