Revision [17500]
This is an old revision of CalcInfo made by JfDelesse on 2007-09-22 17:01:28.
Basic usage
By typing:1 day ={{calc 24*60*60}} seconds
you will obtain:
1 day =86400 seconds
With variables usage
By typing:{{calc total=0}} - red: {{calc q=2;total+=q;q}} - blue: {{calc q=3;total+=q;q}} - yellow: {{calc q=6;total+=q;q}} - **total**: **{{calc total}}**
You will obtain:
- red: 2
- blue: 3
- yellow: 6
- total: 11
Code
Save this as actions/calc.php- <?php
- /*
- *
- *
- */
- {
- function strtonum($str)
- {
- static $calcvar;
- $pattern = '/([^;])+/';
- $varpat='([a-zA-Z]+\s*\(*)';
- $varpattern="/$varpat/";
- $otherpat='([0-9*\-+\/=]+)';
- $allpattern="/$varpat|$otherpat/";
- // print ($allpattern);
- foreach ($blocks[0] as $k=>$block)
- {
- $affichage=true;
- $blockstr="";
- foreach ($out as $k2=>$token)
- {
- if ($token[1]!="")
- {
- $tokstr='$calcvar[\''.$token[1].'\']';
- }
- if ($token[2]!="")
- {
- $tokstr=$token[2];
- {
- $affichage=false;
- }
- }
- $blockstr.=$tokstr;
- }
- {
- $blockstr="$blockstr;";
- if ($affichage)
- $outstr.=($outstr!=""?";":"").$blockstr ;
- }
- }
- return $outstr;
- }
- }
- {
- print strtonum($vars['wikka_vars']);
- }
- ?>