Reputation: 5316
I am running a page with url like this http://www.domain.com/test/reports/index.php
I need to get the url using php with out index.php like
http://www.domain.com/test/reports/
Upvotes: 0
Views: 165
Reputation: 8863
Use parse_url:
$url = (($_SERVER['HTTPS']=="on")?"https://":"http://").$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URL'];
$parts = parse_url($url);
$urlpath = $parts['scheme']."://".$parts['host'].$parts['path'];
Upvotes: 2
Reputation: 638
a noob way to do this with explode implode
<?php
$url = "http://www.domain.com/test/reports/index.php";
$newurl = explode("/", $url);
array_pop($newurl);
implode("/",$newurl);
?>
Upvotes: 0
Reputation: 3665
To be thorough, you'll want to start with parse_url().
$parts=parse_url("http://domain.com/user/100");
That will give you an array with a handful of keys. The one you are looking for is path
.
Split the path on /
and take the last one.
$path_parts=explode('/', $parts['path']);
Your ID is now in $path_parts[count($path_parts)-1]
.
Upvotes: 0
Reputation: 1219
<?php
$url = 'http://www.domain.com/test/reports/index.php';
$file_name = basename($url);
echo str_replace($file_name, '', $url);
?>
Upvotes: 0