0
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/

user1692333
  • 2,461
  • 5
  • 32
  • 64

3 Answers3

1

You can use substr() and strrpos():

$url = '/users/dev/index.php';
echo substr($url, 0, strrpos($url, '/'));
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
0

Use regex if you have different .php file names

$s = '/users/dev/index.php';

preg_match('~^(.*?)([^/]+\.php)~', $s, $m);
print_r($m);

Use substr() if you only have index.php

$m = substr($s, 0, strpos($s, 'index.php'));
print_r($m);
Glavić
  • 42,781
  • 13
  • 77
  • 107
0

check this

print_r(pathinfo($_SERVER['REQUEST_URI'],PATHINFO_DIRNAME));
webCoder
  • 2,192
  • 1
  • 16
  • 29