Reputation: 2597
echo $_SERVER['REQUEST_URI']."\n";
echo strrchr($_SERVER['REQUEST_URI'], '/');
strrchr
returns the same adress as it was before, but i need all until last /.
Update:
$_SERVER['REQUEST_URI'] = /users/dev/index.php
i need /users/dev/
Upvotes: 0
Views: 84
Reputation: 2222
check this
print_r(pathinfo($_SERVER['REQUEST_URI'],PATHINFO_DIRNAME));
Upvotes: 0
Reputation: 43552
$s = '/users/dev/index.php';
preg_match('~^(.*?)([^/]+\.php)~', $s, $m);
print_r($m);
$m = substr($s, 0, strpos($s, 'index.php'));
print_r($m);
Upvotes: 0
Reputation: 39704
You can use substr()
and strrpos()
:
$url = '/users/dev/index.php';
echo substr($url, 0, strrpos($url, '/'));
Upvotes: 1