有天在努力的搜索计算器,发现都是JavaScript,而且要一个个地点击,并且不能记录,输入计算式子时容易出错,于是就想了想该怎样才能让它好用点呢,能够用键盘直
找了很久,发现网上资料很少,美国服务器,香港空间,于是想自己动手写,慢慢的发现问题多了,自己不怎么通算法,写一个计算式子短点还好,长了就挂了,再长点恐怕就要死机。
有一天做做mysql突然发现原来mysql功能这么强大,可以直接计算字符串。。。哈哈 这下可就高兴了。
代码还超级简单 就做了一个ajax的计算器
有式子错误提示 还可以时时显示输入的式子
有兴趣的朋友可以看看 更多的功能可以自己去开发
演示地址:
jquer.js自己去下载
jsq1.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('你输入的式子有错误');
$rs=mysql_fetch_array($res);
echo $rs[0];
?>
jsq.php
复制代码 代码如下:
手写输入计算器 |
在这里你可以手写式子计算哦,还不快试试! 返回首页 |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 English version
Recommended: Win version, supports code prompts!
