CodeIgniter Forums
URI Helper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: URI Helper (/showthread.php?tid=49778)



URI Helper - El Forum - 03-03-2012

[eluser]Uplift[/eluser]
Is it possible to grab the uri segment after a dash.

take the uri

website.com/one-two-three

how would i grab the segment 'three'.. or anything after the second - (dash)

Thanks Smile


URI Helper - El Forum - 03-12-2012

[eluser]Otemu[/eluser]
An option would be to grab the whole segment one-two-three
$afterSecondDash = $this->uri->segment(1);

and then use a regular expression to grab all the letters after the second dash
$afterSecondDash = preg_replace("insert_expression_here", $afterSecondDash );

Sadly I dont know the regular expression that will achieve this which is why I have left the text insert_expression_here, there couple of tutorials you can check out on regular expression:
http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers
http://webcheatsheet.com/php/regular_expressions.php
http://php-regex.blogspot.com/

Hopefully that helps







URI Helper - El Forum - 03-12-2012

[eluser]Aken[/eluser]
Grab the segment, then use explode() to separate the chunks, and end() to get the last one.