Dynamically loading function arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi 

Currently we are building a basic content management system where we
would like to be able to write as libral customized tags as possible,

for example  [[select:array_name,title]] or [[form:name]] in the
format of [[<function>:<arguments>]]

The problem that we are experiencing are that the arguments are being
parsed as a single string, does anybody know of what function / method
i can use to get around this? My default option is to write the
functions to split the single supplied argument into their respective
arguments, but i am sure there is a easier way around?

I have tried splitting them up, and rejoining them with a "," but i
think i am just redoing what php does internally.

Here is my current code,
<?php

// function = select, array = _title_,  name= select_title

$str = "{{select:_title_,select_title}}";  

parse($str);

function parse($str){
            $reg_ex  = '/\{\{([a-zA-Z0-9\-_]+):(.*)\}\}/';   //
{{function_name:paramaters,seperate,by,comma}}
            preg_match_all($reg_ex,$str,$matches,PREG_SET_ORDER);
            // $matches[0] = whole function 
            // $matches[1] = function
            // $matches[2] = content / params
            
           echo $match_count = count($matches);
                for ($i=0;$i<$match_count;$i++){
                    $output = null;
                    if(function_exists($matches[$i][1])){
                        //function has been declared 
			// TO-DO: add safe mode function array to specify allowed functions
						#echo " DEBUG: {$matches[$i][1]} ( {$matches[$i][2]} ) <br
/>\n";
				$args = explode(",",$matches[$i][2]);
				$cnt = count($args);
				$params = null;
				for($j=0; $j < $cnt; $j++){
					#$params .= "\$args[$j]";
					$params .= $args[$j];
					$params .= ($j != ($cnt-1))? ",": "";
				}// end for 
			        //eval("echo $params;");
                                //$output =
$matches[$i][1](implode(",",$args));//single str
 			       $output = $matches[$i][1]($params);
	                       $str = eregi_replace($matches[$i][0],$output,$str);
      	           } //end if 
                   else {
				// function not found or allowed remove tags
				//echo "DEBUG: function not found<br />\n";
                  		$str = eregi_replace($matches[$i][0],'',$str);
                   }// end else 		
                }//end for
          return $str;  
  }
  
  function select($array='',$name='',$extra=''){
  		echo '<pre>';
  		print_r(func_get_args());
		echo '</pre>';
  }
?>

Kind regards 
Jarratt

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux