[wd_asp elements=’search’ ratio=’100%’ id=1]

How to find the last folder in url

14th December 2020

Php - Miscellaneous

php codehaven

If this is my url I am running the script in
http://aq.gthex.co.uk:10000/webcontent/mylogin.php
and I want to find the part called webcontent
use the script below to find this part.


$path = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$array = explode('/',$path);
$count = count($array);
$actualurl = $array[$count-2];

The result will be: webcontent