Hi All
I am using PHP 7.3 and am struggling to find the right code to find the right code to get my filename and all extension info from the URL.
An example URL is:
https://www.domain.com.au/dev/website/shop-product.php?shopCategoryID=1&shopSubCategoryID=2&productID=1&title=Buy%20Blank%20T-Shirts%20Online&category=Men%27s%20T-Shirts
I want to get:
shop-product.php?shopCategoryID=1&shopSubCategoryID=2&productID=1&title=Buy%20Blank%20T-Shirts%20Online&category=Men%27s%20T-Shirts
Can anyone help me out or point me in the right direction please.
mrmbarnes
Hi @mrmbarnes I think something like the following should do the trick (hopefully as I haven’t tested it)
<?php
$url = $_SERVER['REQUEST_URI'];
$urlParts = explode('/', $url);
$urlString = array_pop($urlParts);
echo $urlString;
?>
Thanks… how do I get the URL from the browser tab?
The answer is simple and I’m tempted to give it to you, but it is so simple you should probably google it! 
Edit: updated code in answer above
Thanks… for anyone else who might find this thread this is what worked for me in the end:
<?php
$url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$urlParts = explode('/', $url);
$urlString = array_pop($urlParts);
echo $urlString;
?>
Or you could use parse_url.
2 Likes
Yeah thought about it too, but it doesn’t seem that wil return exactly the fragment he needs…
2 Likes
system
Closed
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.