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

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
try:

<?php
$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?

correct name for it is: sqrt
sqrt(9)=3

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.

Member Avatar

diafol

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?

Member Avatar

diafol

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.