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
Copy codeThe Code is as follows:
<? Php
// 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 ('<font color = red> the formula you entered has an error </font> ');
$ Rs = mysql_fetch_array ($ res );
Echo $ rs [0];
?>
Jsq. php
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> handwritten input calculator </title>
<Meta name = "keywords" content = "online calculator, input formula, and handwritten calculator"/>
<Meta name = "description" content = "online calculator, handwritten input calculator, input formula, and direct calculation"/>
<Script src = "jquery. js" language = "javascript"> </script>
<Script language = "javascript">
$ (Function (){
$ ("# T_ask"). keyup (function (){
$. Post (
"Jsq1.php ",
{
T_ask: $ ("# t_ask"). val ()
}, Function (data, textStatus)
{
$ ("# Res" pai.html (data );
}
);
});
});
</Script>
</Head>
<Body>
<Table width = "800" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td align = "center" height = "40"> </Tr>
</Table>
<Table width = "800" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td height = "34" align = "center"> here you can write a subcomputation. Try again later! <A href = "http://www.jianlila.com"> back to home </a> </td>
</Tr>
</Table>
<Form method = "post">
<Table width = "800" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td width = "27%" align = "right"> formula: </td>
<Td width = "73%"> <textarea name = "t_ask" cols = "60" rows = "6" id = "t_ask"> </textarea> </td>
</Tr>
<Tr>
<Td height = "23" align = "right" >=</td>
<Td> <div id = "res"> </div> </td>
</Tr>
<Tr>
<Td height = "31" align = "right"> </td>
<Td> <input type = "button" name = "tj" id = "tj" value = "button"/>
<Input type = "reset" name = "qc" id = "qc" value = "reset"/> </td>
</Tr>
</Table>
<Table width = "800" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td> <p> Note: <br/>
Trigonometric function:
<P> sin (60) sine cos (60) cosine tan (60) tangent cot (60) cotangent
<P> asin (0.5) arcsin acos (0.5)
Arccosine atan (0.5) arc tangent
<P> abs (-1) = 1 absolute value ceil (0.1) = 1 first
<P> exponential logarithm
<P> exp (float arg) // calculate the <strong> e </strong> (base of natural logarithm) Exponent
<P> log (10,100) = 2 // natural logarithm pow (2, 4) = 16 exponent sqrt (4) = 2 square root
<P> <br/>
</Td>
</Tr>
</Table>
</Form>
</Body>
</Html>