当前位置: 网学 > 编程文档 > PHP > 正文

利用php+mysql来做一个功能强大的在线计算器

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/23

鉴于大家对PHP十分关注,我们编辑小组在此为大家搜集整理了“利用php+mysql来做一个功能强大的在线计算器”一文,供大家参考学习!

找了很久,发现网上资料很少,于是想自己动手写,慢慢的发现问题多了,自己不怎么通算法,写一个计算式子短点还好,长了就挂了,再长点恐怕就要死机。

有一天做做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( 利用php+mysql来做一个功能强大的在线计算器_网学
浏览:
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号
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">&l

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号