. */ /** * @author Brian Shaw * @uses This function is to take the uri and break it into segments. * The function started as being 100% reliant on mod_rewrite to work. * Now it will take either of the following and use it so it works with * or without mod_rewrite * * http://entertainment-tonight.dev/thetest/uri.php?blah=t&he=file * http://entertainment-tonight.dev/thetest/uri.php/blah/t/he/file * http://entertainment-tonight.dev/thetest/uri/blah/t/he/file * * If given either of these above uri's * echo uri_seg(); // returns * array(6) { * [0]=> string(7) "thetest" * [1]=> string(3) "uri" * [2]=> string(4) "blah" * [3]=> string(1) "t" * [4]=> string(2) "he" * [5]=> string(4) "file" * } * echo uri_seg(0); // returns "thetest" * echo uri_seg(1); // returns "uri" * * If invalid data is passed or if the argument passed is not a valid key nothing is returned * */ function uri_seg($segment_id='all') { if (is_null($segment_id)) $segment_id='all'; $uri=stripslashes(strip_tags($_SERVER['REQUEST_URI'])); if (strstr($uri,'.php')) $uri=str_replace(array('.php','?','&','='),array('','/','/','/'),$uri); $uri_segs=explode('/',$uri); array_shift($uri_segs); switch ($segment_id) { case 'all': if ($segment_id=='0') return $uri_segs[0]; if ($segment_id=='all') return $uri_segs; break; default: if (array_key_exists($segment_id,$uri_segs)) return $uri_segs[$segment_id]; break; } } echo "
"; print var_dump(uri_seg()); echo "
"; //echo uri_seg(0); ?>