Discuz checkformulacredits函数 检查积分公式语法
//检验积分公式语法
function checkformulacredits($formula) {
return checkformulasyntax(
$formula,
array('+', '-', '*', '/', ' '),
array('extcredits', 'digestposts', 'posts', 'threads', 'oltime', 'friends', 'doings', 'polls', 'blogs', 'albums', 'sharings')
);
}
function checkformulasyntax($formula, $operators, $tokens) {
$var = implode('|', $tokens);
$operator = implode('', $operators);
$operator = str_replace(
array('+', '-', '*', '/', '(', ')', '{', '}', '\''),
array('\+', '\-', '\*', '\/', '\(', '\)', '\{', '\}', '\\\''),
$operator
);
if(!empty($formula)) {
if(!preg_match("/^([$operator\.\d\(\)]|(($var)([$operator\(\)]|$)+))+$/", $formula) || !is_null(eval(preg_replace("/($var)/", "\$\\1", $formula).';'))){
return false;
}
}
return true;
}
页:
[1]