nelsok1 Posted June 26, 2008 Share Posted June 26, 2008 I want to be able to break a part the output from $_SERVER['REQUEST_URI'] so that http://domain.tld/database/category/food/index.php will return $top_level = database $second_level = category $third_level = food any ideas? Thanks. Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 <?php $url_array=explode("/", $_SERVER['REQUEST_URI']); // do your stuff ?> Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 26, 2008 Share Posted June 26, 2008 If you want to assign variables to each segment of the URI use: $segments = explode("/", $_SERVER['REQUEST_URI']); list($top_level, $second_level, $third_level) = $segments; Quote Link to comment Share on other sites More sharing options...
nelsok1 Posted June 26, 2008 Author Share Posted June 26, 2008 <?php $segments = explode("/", $_SERVER['REQUEST_URI']); list($top_level, $second_level, $third_level) = $segments; echo $top_level; ?> results in Notice: Undefined offset: 2 in index.php on line 16 I am pretty sure it is because this is being at the document root level. Would you suggest counting the number of expoded items? because the directory depth can vary. Quote Link to comment Share on other sites More sharing options...
Wolphie Posted June 26, 2008 Share Posted June 26, 2008 If that's the case, then you shouldn't use list(). list() assumes a known amount of elements in an array. Using the example you provided, exploding it would only make the array have 3 elements, therefore if the array were to have 4 elements you wouldn't be able to use list() because the amount of elements wouldn't be definite. In which case, you should ditch list(). Quote Link to comment Share on other sites More sharing options...
nelsok1 Posted June 26, 2008 Author Share Posted June 26, 2008 do you have another suggestion besides list that will assign a variable to each directory level knowing that it can be variable in length? Quote Link to comment Share on other sites More sharing options...
LemonInflux Posted June 26, 2008 Share Posted June 26, 2008 foreach() loop and variable variables? A bit confusing, but it should work ---------------- Now playing: Augustana - I Still Ain't Over You via FoxyTunes Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.