I want to last two uri segment. just for example i have one url like:
www.abcd.com/country/state/city
AND Next time this url is dynamic so like this:
www.abcd.com/grade/country/state/city
i want to last two uri segments, please help and solve this problem.
You can use uri segments like so. Any thing after www.abcd.com/
is a uri segment
echo $this->uri->segment(1); // This should echo grade
echo $this->uri->segment(2); // This should echo country
echo $this->uri->segment(3); // This should echo state
echo $this->uri->segment(4); // This should echo city
Segment userguide
You can achieve it by using
if ($this->uri->segment(1) == "country") {
echo $this->uri->segment(2); // echo state
echo $this->uri->segment(3); // echo city
}
if ($this->uri->segment(1) == "grade") {
echo $this->uri->segment(3); // echo state
echo $this->uri->segment(4); // echo city
}
Yaah, i have found solution of this problem
$record_num = $this->uri->segment_array();
echo "last - ".$record_num[count($record_num)];
echo "<br>second last - ".$record_num[count($record_num)-1];
exit;