让ecshop模板支持php运算

 
更多

在 cls_template.php 底部加入函数:

/*** 
*
*处理math中的公式. 
*
***/

function get_math_para($val) { 
 $pa = $this->str_trim ( $val );
 foreach ( $pa as $value ) 
 {  
  if (strrpos ( $value, '=' )) 
  {   
   list ( $a, $b ) = explode ( '=', str_replace ( array (' ', '"', "'", '"' ), '', $value ) );   
   if (strpos ( $b, '$' ) >= 0) 
   {   
    //$b为类似的1+2,$abc*123等    
    $pattern = "/\\$[_a-zA-z]+[a-zA-Z0-9_]*/";    
    preg_match ( $pattern, $b, $arr );    
    if ($arr) {     
     foreach ( $arr as $match ) {      
      $v = $this->get_val ( substr ( $match, 1 ) );      
      $b = str_replace ( $match, $v, $b );     
     }    
    }   
   }  
  }
 } 
 return $b;
}

 在大概530行处加入:

case 'math': 
	$t= $this->get_math_para(substr($tag, 8)); 
	return'<?php echo '. $t. '; ?>'; 
	break;

前台模板调用:

{math equation=”$key+1″}

这里注意用双引号。

No related content found.

 

打赏

本文固定链接: https://www.cxy163.net/archives/1002 | 绝缘体

该日志由 绝缘体.. 于 2016年02月05日 发表在 ECSHOP 分类下,
原创文章转载请注明: 让ecshop模板支持php运算 | 绝缘体

报歉!评论已关闭.