lest say I have a inputbox in html and I want to compute the answer to ..hmm lets say

1 + 2 - 1 * 6 + 8 / 2

want is the basic function for this? you can just teach me the basics, or advice something . I'm new to PHP

5 Years
Discussion Span
Last Post by diafol

in real if you just set it to calculate this directly it will do it :)
php is making math calculations so it will calculate this for you

$var=1 + 2 - 1 * 6 + 8 / 2;
echo $var; ?>

oh. thanks man.

I have another question , how about I add a square root added to the above example like

1 + 2 - 1 * 6 + 8 / 2 + √2

should I make anther function for the sqr root?


ok I get it, but lets say I have button for sqrt which will add the sqrt symbol in the input area . but how do I exactly compute the sqrt if inside the input is the symbol.


you can't use the symbol.
you just use sqrt().
If you want a visual, use the html character number for the symbol, but don't use this in the calculation.
alternatively, use pow($number,0.5), but that isn't an improvement.

You can't read the input box and get php to evaluate it, you'll need to use substitution and possibly reorganization to get it to work.


ah yes , it just echoed my inputs . how do I make it compute?


You can't read the input box and get php to evaluate it

unless input box has readable php format, which it probably won't.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.