Search code examples
phpurlpreg-replaceparse-url

Strip the last part off a url


Possible Duplicate:
extract last part of a url

I have a url like this:

http://www.domain.co.uk/product/SportingGoods/Cookware/1/B000YEU9NA/Coleman-Family-Cookset

I want extract just the product name off the end "Coleman-Family-Cookset"

When I use parse_url and print_r I end up with the following:

Array (
    [scheme] => http
    [host] => www.domain.co.uk
    [path] => /product/SportingGoods/Cookware/1/B000YEU9NA/Coleman-Family-Cookset
) 

How do I then trim "Coleman-Family-Cookset" off the end?

Thanks in advance


Solution

  • $url = 'http://www.domain.co.uk/product/SportingGoods/Cookware/1/B000YEU9NA/Coleman-Family-Cookset';
    $url = explode('/', $url);
    $last = array_pop($url);
    echo $last;