码迷,mamicode.com
首页 > Web开发 > 详细

让ecshop模板支持php运算

时间:2016-12-26 12:00:59      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:return   trim   str   bst   lod   array   pattern   ecs   this   

让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"}

让ecshop模板支持php运算

标签:return   trim   str   bst   lod   array   pattern   ecs   this   

原文地址:http://www.cnblogs.com/zhanghu/p/6221771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!