codeigniterCodeIgniter URI Segment

URI Segments:

For example, please consider the following URI:

Segment allows to retrieve a specific segment form URI string where n is a segment number. Segments are numbered from left to right. For example, the following code:


Is used to retrieve a specific segment from the URI where n is the segment number.

echo $this->uri->segment(0);//it will print
echo $this->uri->segment(1);//it will print questions
echo $this->uri->segment(2);//it will print some-number
echo $this->uri->segment(3);//it will print how-can-i-do-this
echo $this->uri->segment(4);//it will print others

Get last and before last URI segment

Get last segment

echo end($this->uri->segment_array()); //it will print others

Get before last segment

echo $this->uri->segment(count($this->uri->segment_array())-1); //it will print how-can-i-do-this

More info: [][1]