Jump to content

breaking up the uri


nelsok1

Recommended Posts

<?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.

Link to comment
https://forums.phpfreaks.com/topic/112087-breaking-up-the-uri/#findComment-575434
Share on other sites

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().

Link to comment
https://forums.phpfreaks.com/topic/112087-breaking-up-the-uri/#findComment-575441
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.