Task as defined:User needs to be able to define their own variables and formulas to operate on those variables, to get output based on their inputs.  Since formulas and variables and their inputs change often, user needs to have control. Example//inputs (may be entered directly or provided by database)$a = 4;$b = 6;//formulas:$c = $a + $b * 5.35;//outputsprint $c;This is to be entered by a user into i.e. a textbox on a website, and have that be saved as master template to be used to compute the author's computations.Thought #1Use PHP Eval:   (function that runs arbitrary source code)But ... If eval() is the answer, you're almost certainly asking the wrong question.   -- Rasmus Lerdorf, BDFL of PHPbut eval() may actually work well for this, but that meanssanitizing inputsfiltering outputsallowing expected user and unexpected (malicious) users free run of evalteaching users subset of PHPThought #2Implement a simple parser for a simple language (i.e capable of processing the above example).  It is a tad more work, or a bit more work depending on what functionality users will ask for and how the project will develop in the future.QuestionAre there any other ways to solve this problem?  In effect, I am designing a module that is supposed to work like a mini-Excel spreadsheet, with power of using arbitrary user-modifiable formulas and variables, and outputs.
How to accomplish a task of evaluating editable variables and formulas, using PHP?
design;php;evaluation