利用php+mysql來(lái)做一個(gè)功能強(qiáng)大的在線計(jì)算器
更新時(shí)間:2010年10月12日 09:53:20 作者:
有天在努力的搜索計(jì)算器,發(fā)現(xiàn)都是JavaScript,而且要一個(gè)個(gè)地點(diǎn)擊,并且不能記錄,輸入計(jì)算式子時(shí)容易出錯(cuò),于是就想了想該怎樣才能讓它好用點(diǎn)呢,能夠用鍵盤直接輸入。
找了很久,發(fā)現(xiàn)網(wǎng)上資料很少,于是想自己動(dòng)手寫,慢慢的發(fā)現(xiàn)問題多了,自己不怎么通算法,寫一個(gè)計(jì)算式子短點(diǎn)還好,長(zhǎng)了就掛了,再長(zhǎng)點(diǎn)恐怕就要死機(jī)。
有一天做做mysql突然發(fā)現(xiàn)原來(lái)mysql功能這么強(qiáng)大,可以直接計(jì)算字符串。。。哈哈 這下可就高興了。
代碼還超級(jí)簡(jiǎn)單 就做了一個(gè)ajax的計(jì)算器
有式子錯(cuò)誤提示 還可以時(shí)時(shí)顯示輸入的式子
有興趣的朋友可以看看 更多的功能可以自己去開發(fā)
演示地址:http://www.jianlila.com/jsq.php
jquer.js自己去下載
jsq1.php
<?php
//鏈接數(shù)據(jù)庫(kù)的
$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);
/*三角函數(shù)替換*/
$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>你輸入的式子有錯(cuò)誤</font>');
$rs=mysql_fetch_array($res);
echo $rs[0];
?>
jsq.php
<html>
<head>
<title>手寫輸入計(jì)算器</title>
<meta name="keywords" content="在線計(jì)算器,輸入式子直接計(jì)算,手寫計(jì)算器" />
<meta name="description" content="在線計(jì)算器,手寫輸入計(jì)算器,輸入式子直接計(jì)算" />
<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>手寫輸入計(jì)算器</h2></td>
</tr>
</table>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="34" align="center">在這里你可以手寫式子計(jì)算哦,還不快試試! <a >返回首頁(yè)</a></td>
</tr>
</table>
<form method="post">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="27%" align="right">計(jì)算式子:</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 />
三角函數(shù):
<p>sin(60)正弦 cos(60)余弦 tan(60)正切 cot(60)余切
<p>asin(0.5)反正弦 acos(0.5)
反余弦 atan(0.5)反正切
<p>abs(-1)=1絕對(duì)值 ceil(0.1)=1進(jìn)一
<p>指數(shù)對(duì)數(shù)
<p>exp(float arg)// 計(jì)算 <strong>e</strong>(自然對(duì)數(shù)的底)的指數(shù)
<p>log(10,100)=2//自然對(duì)數(shù) pow(2,4)=16 指數(shù) sqrt(4)=2平方根
<p><br />
</td>
</tr>
</table>
</form>
</body>
</html>
有一天做做mysql突然發(fā)現(xiàn)原來(lái)mysql功能這么強(qiáng)大,可以直接計(jì)算字符串。。。哈哈 這下可就高興了。
代碼還超級(jí)簡(jiǎn)單 就做了一個(gè)ajax的計(jì)算器
有式子錯(cuò)誤提示 還可以時(shí)時(shí)顯示輸入的式子
有興趣的朋友可以看看 更多的功能可以自己去開發(fā)
演示地址:http://www.jianlila.com/jsq.php
jquer.js自己去下載
jsq1.php
復(fù)制代碼 代碼如下:
<?php
//鏈接數(shù)據(jù)庫(kù)的
$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);
/*三角函數(shù)替換*/
$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>你輸入的式子有錯(cuò)誤</font>');
$rs=mysql_fetch_array($res);
echo $rs[0];
?>
jsq.php
復(fù)制代碼 代碼如下:
<html>
<head>
<title>手寫輸入計(jì)算器</title>
<meta name="keywords" content="在線計(jì)算器,輸入式子直接計(jì)算,手寫計(jì)算器" />
<meta name="description" content="在線計(jì)算器,手寫輸入計(jì)算器,輸入式子直接計(jì)算" />
<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>手寫輸入計(jì)算器</h2></td>
</tr>
</table>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="34" align="center">在這里你可以手寫式子計(jì)算哦,還不快試試! <a >返回首頁(yè)</a></td>
</tr>
</table>
<form method="post">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="27%" align="right">計(jì)算式子:</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 />
三角函數(shù):
<p>sin(60)正弦 cos(60)余弦 tan(60)正切 cot(60)余切
<p>asin(0.5)反正弦 acos(0.5)
反余弦 atan(0.5)反正切
<p>abs(-1)=1絕對(duì)值 ceil(0.1)=1進(jìn)一
<p>指數(shù)對(duì)數(shù)
<p>exp(float arg)// 計(jì)算 <strong>e</strong>(自然對(duì)數(shù)的底)的指數(shù)
<p>log(10,100)=2//自然對(duì)數(shù) pow(2,4)=16 指數(shù) sqrt(4)=2平方根
<p><br />
</td>
</tr>
</table>
</form>
</body>
</html>
您可能感興趣的文章:
- php編程實(shí)現(xiàn)簡(jiǎn)單的網(wǎng)頁(yè)版計(jì)算器功能示例
- PHP實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能
- PHP房貸計(jì)算器實(shí)例代碼,等額本息,等額本金
- PHP實(shí)現(xiàn)簡(jiǎn)單計(jì)算器小程序
- PHP基于堆棧實(shí)現(xiàn)的高級(jí)計(jì)算器功能示例
- PHP基于工廠模式實(shí)現(xiàn)的計(jì)算器實(shí)例
- thinkPHP框架實(shí)現(xiàn)的簡(jiǎn)單計(jì)算器示例
- PHP實(shí)現(xiàn)簡(jiǎn)單的計(jì)算器
- php實(shí)現(xiàn)簡(jiǎn)易計(jì)算器
- PHP實(shí)現(xiàn)簡(jiǎn)易圖形計(jì)算器
相關(guān)文章
PHP程序員簡(jiǎn)單的開展服務(wù)治理架構(gòu)操作詳解(二)
這篇文章主要介紹了PHP程序員簡(jiǎn)單的開展服務(wù)治理架構(gòu)操作,結(jié)合實(shí)例形式分析了rpc客戶端與服務(wù)器相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2020-05-05php輸入流php://input使用示例(php發(fā)送圖片流到服務(wù)器)
在做一個(gè)攝像頭拍照然后上傳的功能,php中使用php://input來(lái)獲取內(nèi)容,可以看下面的示例2013-12-12Yii框架通過請(qǐng)求組件處理get,post請(qǐng)求的方法分析
這篇文章主要介紹了Yii框架通過請(qǐng)求組件處理get,post請(qǐng)求的方法,結(jié)合實(shí)例形式分析了Yii框架請(qǐng)求組件的調(diào)用及處理get、post請(qǐng)求的相關(guān)操作技巧,需要的朋友可以參考下2019-09-09Yii框架實(shí)現(xiàn)記錄日志到自定義文件的方法
這篇文章主要介紹了Yii框架實(shí)現(xiàn)記錄日志到自定義文件的方法,結(jié)合實(shí)例形式分析了Yii框架日志記錄的原理及自定義日志記錄的相關(guān)配置與實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-05-05Zend Framework教程之響應(yīng)對(duì)象的封裝Zend_Controller_Response實(shí)例詳解
這篇文章主要介紹了Zend Framework教程之響應(yīng)對(duì)象的封裝Zend_Controller_Response用法,結(jié)合實(shí)例形式詳細(xì)分析了響應(yīng)對(duì)象的邏輯原理與相關(guān)使用技巧,需要的朋友可以參考下2016-03-03PHP使用CURL獲取302跳轉(zhuǎn)后的地址實(shí)例
這篇文章主要介紹了PHP使用CURL獲取302跳轉(zhuǎn)后的地址實(shí)例,需要的朋友可以參考下2014-05-05Laravel 6.2 中添加了可調(diào)用容器對(duì)象的方法
Laravel小組上周發(fā)布了v6.2.0 版本,接下來(lái)通過本文給大家分享Laravel 6.2 中添加了可調(diào)用容器對(duì)象的方法,需要的朋友可以參考下2019-10-10