One day, I tried to search the calculator and found that it was JavaScript, and I had to click it one by one, but it could not be recorded. it was easy to make mistakes when I entered the formula, so I thought about how to make it easy to use. I can enter it directly on the keyboard. After searching for a long time, I found that there was very little information on the Internet, so I wanted to write it myself. I slowly found that there were many problems. I didn't know how to use algorithms, but it was okay to write a computing formula, if it is longer, it will go down. if it is longer, I am afraid it will crash.
One day when I was doing mysql, I suddenly found that mysql was so powerful that I could directly compute strings... Haha.
The code is also very simple, so I made an ajax calculator.
You can also display input sub-statements at any time when a suberror is prompted.
If you are interested, you can develop more functions by yourself.
Demo address: http://www.jianlila.com/jsq.php
Download jquer. js by yourself
Jsq1.php
The code is as follows:
// Link to the database
$ Db = mysql_connect ("localhost", "root", "123 ");
Header ("Content-Type: text/html; charset = GB2312 ");
$ Str = iconv ('utf-8', 'gbk', trim ($ _ POST ['t _ ask ']);
$ Str = str_replace ("", "", str_replace ("\ r \ n", "", $ str ));
$ Str = str_replace ("(", "(", $ str );
$ Str = str_replace (")", ")", $ str );
/* Trigonometric function replacement */
$ Str = preg_replace ("/sin \((. *) \)/is "," sin (\ $ {1} * pi ()/180) ", $ str); // replace sin
$ Str = preg_replace ("/cos \((. *) \)/is "," cos (\ $ {1} * pi ()/180) ", $ str); // replace cos
$ Str = preg_replace ("/tan \((. *) \)/is "," tan (\ $ {1} * pi ()/180) ", $ str); // replace tan
$ Str = preg_replace ("/cot \((. *) \)/is "," 1/tan (\ $ {1} * pi ()/180) ", $ str); // replace the cotangent
$ Str = preg_replace ("/asin \((. *) \)/is "," asin (\ $ {1}/pi () * 180) * 180/pi () ", $ str); // returns the arc sine.
$ Str = preg_replace ("/acos \((. *) \)/is "," acos (\ $ {1}/pi () * 180) * 180/pi () ", $ str); // returns the arc cosine
$ Str = preg_replace ("/atan \((. *) \)/is "," atan (\ $ {1}/pi () * 180) * 180/pi () ", $ str); // replace the arc tangent
$ SQL = "select". $ str;
$ Res = mysql_query ($ SQL, $ db) or die ('Your input formula has an error ');
$ Rs = mysql_fetch_array ($ res );
Echo $ rs [0];
?>
Jsq. php
The code is as follows:
Handwritten input calculator