<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. 利用php+mysql來做一個功能強大的在線計算器

    時間:2025-12-17 04:16:43 php語言

    利用php+mysql來做一個功能強大的在線計算器

      有天在努力的搜索計算器,發現都是JavaScript,而且要一個個地點擊,并且不能記錄,輸入計算式子時容易出錯,于是就想了想該怎樣才能讓它好用點呢,能夠用鍵盤直接輸入。就跟隨小編去看看吧!

      代碼還超級簡單 就做了一個ajax的計算器

      有式子錯誤提示 還可以時時顯示輸入的式子

      演示地址:/pic/jsq.php

      jquer.js自己去下載

      jsq1.php

      復制代碼 代碼如下:

      <?php

      /pic/p>

      $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);/pic/p>

      $str=preg_replace("/cos\((.*)\)/is","cos(\${1}*pi()/180)",$str);/pic/p>

      $str=preg_replace("/tan\((.*)\)/is","tan(\${1}*pi()/180)",$str);/pic/p>

      $str=preg_replace("/cot\((.*)\)/is","1/tan(\${1}*pi()/180)",$str);/pic/p>

      $str=preg_replace("/asin\((.*)\)/is","asin(\${1}/pi()*180)*180/pi()",$str);/pic/p>

      $str=preg_replace("/acos\((.*)\)/is","acos(\${1}/pi()*180)*180/pi()",$str);/pic/p>

      $str=preg_replace("/atan\((.*)\)/is","atan(\${1}/pi()*180)*180/pi()",$str);/pic/p>

      $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="/pic/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><p id="res"></p></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)/pic/strong>(自然對數的底)的指數

      <p>log(10,100)=2/pic/p>

      <p><br />

      </td>

      </tr>

      </table>

      </form>

      </body>

      </html>

    【利用php+mysql來做一個功能強大的在線計算器】相關文章:

    PHP簡單在線計算器功能示例03-12

    如何利用Word來制作“倒福”08-27

    利用inter來記英語單詞12-16

    php+mysql注射語句構造03-17

    如何利用真題來把握自考方向02-16

    如何利用美劇來學習雅思口語02-24

    初一《利用計算器求平均數》教學計劃10-20

    自考復習:如何利用真題來把握考試方向02-05

    利用JS來控制鍵盤的上下左右鍵02-02

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人