您的位置 首页 php

在线PHP软件示例:在线次氯酸盐稀释计算器

在线软件易于使用,无需安装即可运行

您的软件和代码将是安全的,因为它们不会分发给最终用户

您的软件将很容易与您的网站集成

介绍

次氯酸钠溶液广泛用于家庭护理,游泳水消毒,家禽生产厂等。

它最广为人知的商品名称是Clorox。

许多小型工厂购买散装的浓缩溶液进行稀释和包装。

该计算器用于提供稀释的在线计算。

使用此计算器:

确定您要产生的浓度,例如4%w/w

获取您拥有的储备溶液的浓度。

转到在线页面进行计算在线计算器

输入您的值,然后按计算

在线计算器将使用AJAX,因此页面将显示结果而无需重新加载。

所有输入数据将被发送到PHP脚本进行计算。

兴趣点:

本文讨论以下技术:

如何构建可以在免费托管上运行的简单在线软件。

简单植入ajax

在PC上测试软件

托管要求:

免费或付费托管帐户

该软件不需要数据库

托管应支持PHP。

为什么要使用PHP?

即使是免费计划,它也是网络服务器上可用的最多服务器端脚本

它可以在Windows和Unix服务器上运行

在本地测试您的代码

要在本地测试代码,您将需要具有PHP支持的Web服务器。

默认情况下,一些易于使用的支持PHP的服务器的列表。

统一服务器零:统一零重新审视了Apache,MySQL,PHP和Perl的可移植性。它具有电源完全控制面板

XAMPP:这是一个非常常见的基于Apache的Web服务器,具有PHP支持

Server2Go:具有PHP支持的基于Apache的便携式Web服务器。它可以在CD上运行

应用服务

USBWeb服务器

WampServer

您应该通过其他软件添加PHP支持的一些易于使用的服务器列表。

小型HTTP服务器,轻巧,功能强大,多功能的Web服务器。

IIS:IIS是在Windows中内置的,用于添加PHP支持,只需下载PHPforIIs并运行它即可

该应用程序如何工作?

该应用取决于不同单位的浓度表和次氯酸钠溶液的密度。对于每个浓度,它还包含过量的氢氧化钠。

以将8%w/w的溶液稀释为4%的溶液所需的水量为例。

我们在表中搜索输入和输出氯的重量百分比和密度。

如果没有找到浓度,我们将根据最近的浓度进行计算

 //This function will search for a given concentration 
//$var:  value to be searched
//$field:unit of the value 
function searchit($var, $field){
    global $hypochlorite_table;  
    //array contains the data table of chlorine concentrations 
    //and density and reqiured sodium hydroxide
    global $precision;           
    //precision for each field in the $hypochlorite_table array
    $var=round($var,$precision[$field]);
    if ( is_numeric ( $var )) $var = (trim($var) == '')? 0 :$var; else $var = 0;
    for ($index = 0; $index < count($hypochlorite_table); $index++) {
        if($var == $hypochlorite_table[$index][$field]){
            return outputrow($index);
        }elseif($var < $hypochlorite_table[$index][$field]){
            if(!$index) return outputrow($index);
            $delta = ($var-$hypochlorite_table[$index-1][$field])
/($hypochlorite_table[$index][$field]-$hypochlorite_table[$index-1][$field]);
            return outputrow($index,$delta);
        }
    }    
    return false;
}


function outputfield($field,&$row,$index,$delta=0){
    global $hypochlorite_table,$precision;
    if($delta==0){
        $row[$field]= round($hypochlorite_table[$index][$field], 
                $precision[$field]);
    }else{
        $row[$field]=round(
          $hypochlorite_table[$index-1][$field] 
        + $delta*($hypochlorite_table[$index][$field]
        - $hypochlorite_table[$index-1][$field]) 
        , $precision[$field]);
    }
}


function outputrow($index,$delta=0){
    $row=array();
    outputfield(ClWV     ,$row,$index,$delta);
    outputfield(d        ,$row,$index,$delta);
    outputfield(dChange  ,$row,$index,$delta);             
    outputfield(ClWW     ,$row,$index,$delta);
    outputfield(ClDegrees,$row,$index,$delta);
    outputfield(NaOClWV  ,$row,$index,$delta);
    outputfield(NaOClWW  ,$row,$index,$delta);
    outputfield(NaOH     ,$row,$index,$delta);
    outputfield(dNone    ,$row,$index,$delta);
    return $row;
}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253复制代码类型:[php]  

听力是桌子的一部分

将表数据存储在数组中:

有3个数据字段,其他字段为计算字段。

我将数据字段存储在数组中

 $hypochlorite_table =array(
array(00.0, 1.001, 0.012),
array(01.0, 1.020, 0.064),
array(01.5, 1.027, 0.053),
array(02.0, 1.034, 0.050),
array(02.1, 1.035, 0.049),
array(02.5, 1.041, 0.044),
array(02.6, 1.043, 0.041),
........
</pre lang="php">12345678910复制代码类型:[php]  

我定义字段常量

 $fields=array(
0=>'ClWV',       //Cl(%w/v): weight of chlorine in 100 ml of the solution
1=>'d',          //Specific Gravity of Sodium Hypochlorite solution that 
                 //contains default required excess of Sodium Hydroxide
2=>'dChange',    //Specific Gravity change when adding 1% NaOH
3=>'ClWW',       //Cl%= ClWV /d
4=>'ClDegrees',  //°Cl Chlorometric Degrees = = 3.2 * ClWV
5=>'NaOClWV',    //NaOCl% w/v: weight of Sodium Hypochlorite in 100 ml of the solution 
6=>'NaOClWW',    //NaOCl%: weight of Sodium Hypochlorite in 100 g of the solution  
7=>'NaOH',       //NaOH%: Default required excess of Sodium Hydroxide for 
                 //this concentration of hypochlorite=0.25+ClWW*0.75/16
8=>'dNone'       //Specific gravity of Sodium Hypochlorite solution that 
                 //does not contain any excess of Sodium Hydroxide    
);

foreach ($fields as $key => $value) define($value,$key);12345678910111213141516复制代码类型:[php]  

然后,我将计算出的字段存储在数组中以便于搜索。

我写了一个HTML页面,它将作为应用程序的界面

使用AJAX调用PHP数据

用户填写表单并按计算按钮后,它将调用AjaxRefresh函数。

此功能将执行以下操作

将所有表单数据存储在字符串中

创建XMLHttpRequest对象

创建一个将处理AJAX响应的函数

打开XMLHttpRequest对象并发送数据

 function AjaxRefresh(){

var q = 'ajax.php'  + '?id='        + 
'&CIn='         + CIn.value         + 
'&COut='        + COut.value        + 
'&dIn='         + dIn.value         + 
'⟨='        + lang.value        + 
'&NaOHIn='      + NaOHIn.value      + 
'&QOut='        + QOut.value        + 
'&UnitIn='      + UnitIn.value      + 
'&UnitInAr='    + UnitInAr.value    + 
'&UnitOut='     + UnitOut.value     + 
'&UnitOutAr='   + UnitOutAr.value   +
'&UnitQOut='    + UnitQOut.value    +
'&UnitQOutAr='  + UnitQOutAr.value  ;

var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState===4 && xmlhttp.status===200)
    var pairs = xmlhttp.responseText.split('&');
    for(i=0;i<pairs.length;i++){
       var pair = pairs[i].split('=');
       var element = document.getElementById(pair[0]);
        if(element===null){
        }else{ 
            try{element.innerHTML = pair[1].trim();}catch(e){};
            try{element.value = pair[1].trim();}catch(e){};
        };
    };
};
xmlhttp.open("GET",q,true);
xmlhttp.send();
}123456789101112131415161718192021222324252627282930313233复制代码类型:[php]  

PHP脚本将发送HTML元素ID及其新值

文章来源:智云一二三科技

文章标题:在线PHP软件示例:在线次氯酸盐稀释计算器

文章地址:https://www.zhihuclub.com/149881.shtml

关于作者: 智云科技

热门文章

网站地图