I need determine if the current URL ends in /site-map
For example: site.com/site-map
Or
site.com/somedirectory/site-map
Is there a PHP method to pull this value?
You could use substr to check the last 9 characters:
$url = $_SERVER['REQUEST_URI'];
if (substr($url,-9)=="/site-map")
edit to accommodate the url ending with /site-map/ occasionally you could do this:
$url = $_SERVER['REQUEST_URI'];
if (substr($url,-9)=="/site-map" || substr($url,-10)=="/site-map/")
Here's a preg_match()
solution. Likely to be a bit slower than strpos()
& substr()
, but more flexible.
$url = $_SERVER['REQUEST_URI'];
if (preg_match("/\/site-map$/", $url)) {
// it ends in /site-map
}
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