Get slug from current url

php

Solution

This should do exactly that:

trim(parse_url($url, PHP_URL_PATH), '/');

It takes the path and strips the forward slashes on both sides.

To get only the last part of the path:

basename(parse_url($url, PHP_URL_PATH));

Problem

I have URLs like so: ``` http://localhost/hi-every-body/ http://s1.localhost/hello-world/ http://s2.localhost/bye-world/ ``` I want the page "slug" from the URLS, eg. ``` hi-every-body hello-world bye-world ``` What's a simple way of doing this in PHP?

Original source