Revision [17494]

This is an old revision of CalcInfo made by JfDelesse on 2007-09-22 16:19:14.

 

This action allows you to write calculations (with variables) and write out the result.

<?php

/*
 *
 *
 */

 if (!function_exists('strtonum'))
{
  $calcvar=array();
 
  function strtonum($str)
    {
      static $calcvar;
      $pattern = '/([^;])+/';
      $varpat='([a-zA-Z]+\s*\(*)';
      $varpattern="/$varpat/";
      $otherpat='([0-9*\-+\/=]+)';
      $allpattern="/$varpat|$otherpat/";
      //      print ($allpattern);
      preg_match_all($pattern,$str,$blocks);
      foreach ($blocks[0] as $k=>$block)
    {
      $affichage=true;
      $blockstr="";
      preg_match_all($allpattern,$block,$out,PREG_SET_ORDER);
      foreach ($out as $k2=>$token)
        {
          if ($token[1]!="")
        {
          $token[1]=preg_replace('/\s*\(*/','',$token[1]);
          $tokstr='$calcvar[\''.$token[1].'\']';
        }
          if ($token[2]!="")
        {
          $tokstr=$token[2];

          if (!(strpos($tokstr,"=")===false))
            {
              $affichage=false;
            }
        }
          $blockstr.=$tokstr;
        }
      if(!empty($blockstr))
        {

        $blockstr="$blockstr;";
          $blockstr=eval("return ".$blockstr);
          if ($affichage)
        $outstr.=($outstr!=""?";":"").$blockstr ;
        }

    }
    return $outstr;
}
}

if (is_array($vars))
{
  print strtonum($vars['wikka_vars']);
 
}

?>
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki