Search code examples
codeigniterurisegment

Codeigniter: Getting a uri string without the first segment


I have some code in Codeigniter where I have the language code in the first segment of the URI, and I would like to know how to obtain a URI string without the first segment independently of the number of segments the URI might have.

Example: Having this URL:

http://example.com/en/seg1/seg2

This $this->uri->uri_string() will result in en/seg1/seg2

But what I want is only seg1/seg2/etc..

I tried using the for loop to get all segments except the first, but it outputs only 0, like in:

for ($i=2; $i <= $numsegments; $i++) { $string += $this->uri->segment($i); }

I'm out of options. I appreciate your help. Thank you.


Solution

  • You can replace the "en/" using str_replace

    $string=str_replace("","en/",$this->uri->segment($i));
    

    UPDATE

    $pos= strpos('/',$this->uri->segment($i)); //returns position of your first /
    $string = substr($this->uri->segment($i),$pos+1);