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?
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With