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.
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.
After searching for a long time, I found that there was very little information on the Internet, such as the US server and Hong Kong space. So I wanted to write it myself and found that there were too many problems. I didn't know how to use algorithms, it's okay to write a computing formula. If it's longer, it's okay. If it's longer, I'm 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:
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