• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My uri_to_assoc with custom url param

#1
[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);
    }
    
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.