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