Use PHP + MYSQL to create a powerful online calculator

Source: Internet
Author: User
Tags acos asin natural logarithm

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 and I was not very familiar with it. Algorithm 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.

CodeIt's also a simple 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 code The 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 code The 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"> <H2> handwritten input calculator </H2> </TD>
</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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.