<?php
if(isset($_POST["formula"])){
    
   $str = $_POST["formula"];
   $str = str_replace(' ', '', $str);
   $operate = array("-", "+", "/", "*", "(", ")", ".");
   $element = array('');
   
   $strlen = strlen( $str );
   $id = 0;
   $formula='';
   for( $i = 0; $i < $strlen; $i++ ) {
        $char = substr( $str, $i, 1 );
       if(is_numeric( $char ) || in_array($char, $operate)) {
        //echo $char."<br>";
        $formula.=$char;
       }else{
        if(!in_array($char, $element)){
           $id++;
           //echo ("NBR".$id."=".$char."<br>");
           $element[$id] = $char;
           $formula.="VALUE".$id;
        }else{
            $key = array_search($char, $element);
            $formula.="VALUE".$key;
        }
       }

   }

echo $formula."@@@@".$id;
}
?>