--- nfo/php/libs/net.php.smarty/plugins/function.math.php 2002/10/09 00:53:36 1.1
+++ nfo/php/libs/net.php.smarty/plugins/function.math.php 2004/06/16 21:58:17 1.2
@@ -1,12 +1,22 @@
+ * Name: math
+ * Purpose: handle math computations in template
+ * @link http://smarty.php.net/manual/en/language.function.math.php {math}
+ * (Smarty online manual)
+ * @param array
+ * @param Smarty
+ * @return string
*/
function smarty_function_math($params, &$smarty)
{
@@ -25,11 +35,10 @@
}
// match all vars in equation, make sure all are passed
- preg_match_all("![a-zA-Z][a-zA-Z0-9]*!",$equation, $match);
+ preg_match_all("!\!(0x)([a-zA-Z][a-zA-Z0-9_]*)!",$equation, $match);
$allowed_funcs = array('int','abs','ceil','cos','exp','floor','log','log10',
'max','min','pi','pow','rand','round','sin','sqrt','srand','tan');
-
- foreach($match[0] as $curr_var) {
+ foreach($match[2] as $curr_var) {
if (!in_array($curr_var,array_keys($params)) && !in_array($curr_var, $allowed_funcs)) {
$smarty->trigger_error("math: parameter $curr_var not passed as argument");
return;
@@ -55,7 +64,7 @@
if (empty($params['format'])) {
if (empty($params['assign'])) {
- echo $smarty_math_result;
+ return $smarty_math_result;
} else {
$smarty->assign($params['assign'],$smarty_math_result);
}