- //检验积分公式语法
 
  
- function checkformulacredits($formula) {
 
 -         return checkformulasyntax(
 
 -                 $formula,
 
 -                 array('+', '-', '*', '/', ' '),
 
 -                 array('extcredits[1-8]', '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;
 
 - }
 
  复制代码 |