echo $_SERVER['REQUEST_URI']."\n";
echo strrchr($_SERVER['REQUEST_URI'], '/');
strrchr
返回与之前相同的地址,但我需要一直到最后 / 。
更新:
$_SERVER['REQUEST_URI'] = /users/dev/index.php
我需要/users/dev/
答案 0 :(得分:1)
您可以使用substr()
和strrpos()
:
$url = '/users/dev/index.php';
echo substr($url, 0, strrpos($url, '/'));
答案 1 :(得分:0)
$ s ='/users/dev/index.php';
preg_match('~^(.*?)([^/]+\.php)~', $s, $m);
print_r($m);
$m = substr($s, 0, strpos($s, 'index.php'));
print_r($m);
答案 2 :(得分:0)
检查这个
print_r(pathinfo($_SERVER['REQUEST_URI'],PATHINFO_DIRNAME));