-2

I can catch current URL by $_SERVER['REQUEST_URI'] which is /mysitw/project/detail/fp/3 & want to parse like

array(0=>mysite, 1=>project, 2=>detail, 3=>fp, 4=>3)

and then easily search my required value using in_array() which I can do if could parse url successfully in an array

j0k
  • 22,600
  • 28
  • 79
  • 90
PHP Ferrari
  • 15,754
  • 27
  • 83
  • 149
  • Do you have an actual question? –  Sep 24 '12 at 11:54
  • possible duplicate of [PHP - strip URL to get tag name](http://stackoverflow.com/questions/3373936/php-strip-url-to-get-tag-name) – guido Sep 24 '12 at 13:07

2 Answers2

3

If you do this...

$array = explode('/', $_SERVER['REQUEST_URI']);

your array should look like this...

echo $array [0]; // mysite
echo $array [1]; // project
echo $array [2]; // detail
echo $array [3]; // fp
echo $array [4]; // 3
Marcus
  • 8,230
  • 11
  • 61
  • 88
0
$url = $_SERVER['REQUEST_URI'];
$url_splits = parse_url($url);
$path = $url_splits['path'];

$each_elemts = explode("/",$path);

print_r($each_elemts);
Miqdad Ali
  • 6,129
  • 7
  • 31
  • 50