for solving things like 5+5= ?
is easy
just ask the person to give the input as $result = 5+5
then
just eval it and echo $result
for :-
5x+3=8 (solves for x)
one easy way is to have the person to express it in a valid expression form
=> $result = $expression
=> user gives $result = (8-3)/5;
it gets eval'd as in above case.
for a little bit complex case involving multiple variables we can have it the same way
$var1 = 9;
$var2 = $var1*$var1+$var1+8;
$result = sqrt($var1+$var2);
when this is the input there will be no problem.
but for cases like
8*$var1 = $var2
the above method wont work
for these type of case you will need to make a compiler/interpreter (its pretty easy to make for things like this if you know how to 🙂 )
like to solve a linear equation in 1 variable use can use the general form
ax + b = c
where a,b,c are constant and x is the variable, and let the compiler/interpretor return you values of a,b,c
then u can simple calculate x by (c-b)/a
if you move on to more complex equations, the compiler will also become equally complex.
you might like to look as tools LEX and YACC available in linux which will make a compiler for you in C. convert that to php.