This is kind of a weird thing and I'm not sure how to phrase the question. I can't find anything that doesn't involve using eval() on strings that already contain numbers. My strings may contain numbers, but there will be "variables" in there as well.
And eval() is strictly out of the question.
The purpose of this is to allow a third-party to write equations that will be stored in a database. The equation will be retrieved and should be evaluated based on user submitted input.
So for a very basic example, let's take calculating the area of a rectangle. Simple w*h. When pulled from the database, the equation is a string:
(total_width * total_height)
The user submits their numbers $_POST['total_width'] and $_POST['total_height']. The script goes and grabs that formula from the database and needs to translate it to:
$_POST['total_width'] * $_POST['total_height']
The problem is, of course, that the equation is a string and those aren't variables.
I've looked at strtr, extract, variables as variables and various custom classes. I'm hoping there's some cool feature that I haven't found yet (like that generator/yield thing) and that doesn't require some super-massive function.
I created a dummy string of $str = "($one * $two)", but that just displays "(1 * 2)" (If, you know, I pass 1 and 2 into it.)