CodeIgniter Forums
My uri_to_assoc with custom url param - 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: My uri_to_assoc with custom url param (/showthread.php?tid=40598)



My uri_to_assoc with custom url param - El Forum - 04-13-2011

[eluser]Atas[/eluser]
Hello i extended the uri class, now i can do this.

Code:
$this->uri->my_uri_to_assoc($_SERVER['HTTP_REFERER']);

Any comments ? is it ok ?

Code:
class MY_URI extends  CI_URI {
    
    function __construct()
    {
        parent::__construct();
    }
    
    function my_explode_segments($sUrl)
    {
        $segments = array();
        foreach (explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $sUrl)) as $val)
        {
            if ($val != '')
            {
                $segments[] = $val;
            }
        }
        
        $segments = array_slice($segments, 2);        
        
        $i = 0;
        $lastval = '';
        $retval  = array();
        foreach ($segments as $seg)
        {
            if ($i % 2)
            {
                $retval[$lastval] = $seg;
            }
            else
            {
                $retval[$seg] = FALSE;
                $lastval = $seg;
            }

            $i++;
        }
        
        return $retval;
    }
    
    function my_uri_to_assoc($sUrl="")
    {
        if(empty($sUrl)) return false;
        
        $sUrl = str_replace(site_url(), "", $sUrl);
        return $this->my_explode_segments($sUrl);
    }
    
}