利用php+mysql来做一个功能强大的在线计算器
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了利用php+mysql来做一个功能强大的在线计算器,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3289字,纯文字阅读大概需要5分钟。
内容图文
![利用php+mysql来做一个功能强大的在线计算器](/upload/InfoBanner/zyjiaocheng/282/b9a4826487db4c189a1a687e1cd8a15a.jpg)
有一天做做mysql突然发现原来mysql功能这么强大,可以直接计算字符串。。。哈哈 这下可就高兴了。
代码还超级简单 就做了一个ajax的计算器
有式子错误提示 还可以时时显示输入的式子
有兴趣的朋友可以看看 更多的功能可以自己去开发
演示地址:http://www.jianlila.com/jsq.php
jquer.js自己去下载
jsq1.php
代码如下:
<?php
//链接数据库的
$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);
/*三角函数替换*/
$str=preg_replace("/sin\((.*)\)/is","sin(\${1}*pi()/180)",$str);//替换sin
$str=preg_replace("/cos\((.*)\)/is","cos(\${1}*pi()/180)",$str);//替换cos
$str=preg_replace("/tan\((.*)\)/is","tan(\${1}*pi()/180)",$str);//替换tan
$str=preg_replace("/cot\((.*)\)/is","1/tan(\${1}*pi()/180)",$str);//替换余切
$str=preg_replace("/asin\((.*)\)/is","asin(\${1}/pi()*180)*180/pi()",$str);//反正弦
$str=preg_replace("/acos\((.*)\)/is","acos(\${1}/pi()*180)*180/pi()",$str);//反余弦
$str=preg_replace("/atan\((.*)\)/is","atan(\${1}/pi()*180)*180/pi()",$str);//替换反正切
$sql="select ".$str ;
$res=mysql_query($sql,$db) or die('<font color=red>你输入的式子有错误</font>');
$rs=mysql_fetch_array($res);
echo $rs[0];
?>
jsq.php
代码如下:
<html>
<head>
<title>手写输入计算器</title>
<meta name="keywords" content="在线计算器,输入式子直接计算,手写计算器" />
<meta name="description" content="在线计算器,手写输入计算器,输入式子直接计算" />
<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").html(data);
}
);
});
});
</script>
</head>
<body>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" height="40"><h2>手写输入计算器</h2></td>
</tr>
</table>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="34" align="center">在这里你可以手写式子计算哦,还不快试试! <a href="http://www.jianlila.com">返回首页</a></td>
</tr>
</table>
<form method="post">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="27%" align="right">计算式子:</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="按钮" />
<input type="reset" name="qc" id="qc" value="重置" /></td>
</tr>
</table>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><p>说明:<br />
三角函数:
<p>sin(60)正弦 cos(60)余弦 tan(60)正切 cot(60)余切
<p>asin(0.5)反正弦 acos(0.5)
反余弦 atan(0.5)反正切
<p>abs(-1)=1绝对值 ceil(0.1)=1进一
<p>指数对数
<p>exp(float arg)// 计算 <strong>e</strong>(自然对数的底)的指数
<p>log(10,100)=2//自然对数 pow(2,4)=16 指数 sqrt(4)=2平方根
<p><br />
</td>
</tr>
</table>
</form>
</body>
</html>
内容总结
以上是互联网集市为您收集整理的利用php+mysql来做一个功能强大的在线计算器全部内容,希望文章能够帮你解决利用php+mysql来做一个功能强大的在线计算器所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。