I am having a slight trouble. I am wanting to get a find the top level folder and use it as a variable.
For instance.
If I have a url: http://www.someurl.com/foldername/hello.php
I would like to look at the URL and echo 'foldername'.
At present my code strips things so that it echos 'hello.php'.
Any help would be greatly appreciated.
<?php
// Get URL String //
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
// Split String and get folder//
function curPageName() {
return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/"));
}
// Pass along Results //
$foldername = curPageName();
echo $foldername;
?>