|
Posted by RaTT on 10/21/60 11:17
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
[Back to original message]
|