php - Retrieving URL folder name from string -
i having slight trouble. wanting find top level folder , use variable.
for instance.
if have url: http://www.someurl.com/foldername/hello.php
i @ url , echo 'foldername'.
at present code strips things echos 'hello.php'.
any appreciated.
<?php // 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 , folder// function curpagename() { return substr($_server["script_name"],strrpos($_server["script_name"],"/")); } // pass along results // $foldername = curpagename(); echo $foldername; ?>
<?php $a = "http://www.someurl.com/foldername/hello.php"; $b = explode('/',$a); //var_dump($b); // got result array(5) { [0]=> string(5) "http:" [1]=> string(0) "" [2]=> string(15) "www.someurl.com" [3]=> string(10) "foldername" [4]=> string(9) "hello.php" } // or echo foldername store value array in variable
$value = $b['3']; echo $value // output foldername ?> i newbie
Comments
Post a Comment