Say I have the following URL values:
http://website.com/tagged/news/
http://website.com/tagged/news
http://www.website.com/tagged/news/
http://www.website.com/tagged/news
I'd like to have a PHP function to get news in this example. So I want the value after the last slash if it isn't blank and if that value is blank, then I'd like to get the value before that slash.
I found this post: Get last word from URL after a slash in PHP
But I'd like to be really sure just in case someone types a slash at the end of the URL.
As easy as:
substr(strrchr(rtrim($url, '/'), '/'), 1)
You can also use basename($url)
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