时间:2021-07-01 10:21:17 帮助过:50人阅读
- <br><?php <br>//链接数据库的 <br>$db=mysql_connect("localhost","root","123"); <br>header("Content-Type:text/html;charset=GB2312"); <br>$str=iconv('utf-8','gbk',trim($_POST['t_ask'])); <br>$str=str_replace(" ","",str_replace("\r\n","",$str)); <br>$str=str_replace("(","(",$str); <br>$str=str_replace(")",")",$str); <br>/*三角函数替换*/ <br>$str=preg_replace("/sin\((.*)\)/is","sin(\${1}*pi()/180)",$str);//替换sin <br>$str=preg_replace("/cos\((.*)\)/is","cos(\${1}*pi()/180)",$str);//替换cos <br>$str=preg_replace("/tan\((.*)\)/is","tan(\${1}*pi()/180)",$str);//替换tan <br>$str=preg_replace("/cot\((.*)\)/is","1/tan(\${1}*pi()/180)",$str);//替换余切 <br>$str=preg_replace("/asin\((.*)\)/is","asin(\${1}/pi()*180)*180/pi()",$str);//反正弦 <br>$str=preg_replace("/acos\((.*)\)/is","acos(\${1}/pi()*180)*180/pi()",$str);//反余弦 <br>$str=preg_replace("/atan\((.*)\)/is","atan(\${1}/pi()*180)*180/pi()",$str);//替换反正切 <br>$sql="select ".$str ; <br>$res=mysql_query($sql,$db) or die('<font color=red>你输入的式子有错误</font>'); <br>$rs=mysql_fetch_array($res); <br>echo $rs[0]; <br>?> <br> <br>jsq.php <br><span><u></u></span> 代码如下:<pre class="brush:php;toolbar:false layui-box layui-code-view layui-code-notepad"><ol class="layui-code-ol"><li><br><html> <br><head> <br><title>手写输入计算器</title> <br><meta name="keywords" content="在线计算器,输入式子直接计算,手写计算器" /> <br><meta name="description" content="在线计算器,手写输入计算器,输入式子直接计算" /> <br><script src="jquery.js" language="javascript"></script> <br><script language="javascript"> <br>$(function(){ <br>$("#t_ask").keyup(function(){ <br>$.post( <br>"jsq1.php", <br>{ <br>t_ask : $("#t_ask").val() <br>},function(data,textStatus) <br>{ <br>$("#res").html(data); <br>} <br>); <br>}); <br>}); <br></script> <br></head> <br><body> <br><table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <br><tr> <br><td align="center" height="40"><h2>手写输入计算器</h2></td> <br></tr> <br></table> <br><table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <br><tr> <br><td height="34" align="center">在这里你可以手写式子计算哦,还不快试试! <a href="http://www.jianlila.com">返回首页</a></td> <br></tr> <br></table> <br><br><form method="post"> <br><table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <br><tr> <br><td width="27%" align="right">计算式子:</td> <br><td width="73%"><textarea name="t_ask" cols="60" rows="6" id="t_ask"></textarea></td> <br></tr> <br><tr> <br><td height="23" align="right">=</td> <br><td><div id="res"></div></td> <br></tr> <br><tr> <br><td height="31" align="right"></td> <br><td><input type="button" name="tj" id="tj" value="按钮" /> <br><input type="reset" name="qc" id="qc" value="重置" /></td> <br></tr> <br></table> <br><table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <br><tr> <br><td><p>说明:<br /> <br>三角函数: <br><p>sin(60)正弦 cos(60)余弦 tan(60)正切 cot(60)余切 <br><p>asin(0.5)反正弦 acos(0.5) <br>反余弦 atan(0.5)反正切 <br><p>abs(-1)=1绝对值 ceil(0.1)=1进一 <br><p>指数对数 <br><p>exp(float arg)// 计算 <strong>e</strong>(自然对数的底)的指数 <br><p>log(10,100)=2//自然对数 pow(2,4)=16 指数 sqrt(4)=2平方根 <br><p><br /> <br></td> <br></tr> <br></table> <br></form> <br></body> <br></html> <br></li><li> </li><li> </li></ol></pre>