Get pool from current url

I get the urls in the following patterns:

http://localhost/hi-every-body/
http://s1.localhost/hello-world/
http://s2.localhost/bye-world/

and I want to get the exact slug like

hi-every-body
hello-world
bye-world

with very few checks and very few lines of code. I tried, but there were too many checks.

+5
source share
1 answer

This should do just that:

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

It takes a path and removes slashes on both sides.

+13
source

All Articles