![]() |
Transform underscore to dash in segment_array URI function - 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: Transform underscore to dash in segment_array URI function (/showthread.php?tid=35886) |
Transform underscore to dash in segment_array URI function - El Forum - 11-14-2010 [eluser]kitefr[/eluser] Hi guys ! I work with CodeIgniter for a few months now and i come to think about how to change value with underscore in an array to dash ones. Because i wrote my own function to create menu and I'm using dash into the URL instead of underscore as method arguments. The thing is i was using the URI function segment_array() but in take controllers and methods and arguments as the really like : with underscore because the dash ones are only for view and be pretty. so i create my own function to take segment array with dash instead of underscore and i wanted to give to people who maybe need it ! So i made the MY_Uri.php library : Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Put it into your library's application folder and use the function like the other uri function ! Code: ex : $this->uri->dash_segment_array(); So now the array will be like that : Code: Array Instead of like that : Code: Array I'm not a programmer and I'm learning by myself by passion so if someone can make a better code and a cleaner one, I will be interested ! Thank you ^^ Transform underscore to dash in segment_array URI function - El Forum - 11-14-2010 [eluser]InsiteFX[/eluser] str_replace is faster then preg_replace You only need to use preg_replace if using regx InsiteFX Transform underscore to dash in segment_array URI function - El Forum - 11-14-2010 [eluser]tonanbarbarian[/eluser] have a look at the array_walk function http://au2.php.net/manual/en/function.array-walk.php Transform underscore to dash in segment_array URI function - El Forum - 11-15-2010 [eluser]kitefr[/eluser] Thanks i change to str_replace instead ![]() for array_walk i'm still trying to understand how to use it... ^^; |