Changeset 2504

Show
Ignore:
Timestamp:
04/15/2008 11:08:12 AM (7 months ago)
Author:
Shadowhand
Message:

Added arr::callback_string()

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/helpers/arr.php

    r2489 r2504  
    1111 */ 
    1212class arr_Core { 
     13 
     14        /** 
     15         * Return a callback array from a string, eg: limit[10,20] would become 
     16         * array('limit', array('10', '20')) 
     17         * 
     18         * @param   string  callback string 
     19         * @return  array 
     20         */ 
     21        public function callback_string($str) 
     22        { 
     23                // command[param,param] 
     24                if (preg_match('/([^\[]*+)\[(.+)\]/', (string) $str, $match)) 
     25                { 
     26                        // command 
     27                        $command = $match[1]; 
     28 
     29                        // param,param 
     30                        $params = preg_split('/(?<!\\\\),/', $match[2]); 
     31                        $params = str_replace('\,', ',', $params); 
     32                } 
     33                else 
     34                { 
     35                        // command 
     36                        $command = $str; 
     37 
     38                        // No params 
     39                        $params = NULL; 
     40                } 
     41 
     42                return array($command, $params); 
     43        } 
    1344 
    1445        /**