markdown转换脚本_使用此PHP脚本转换温度

markdown转换脚本

This PHP script can be used to convert temperature values to or from Celsius, Fahrenheit, Kelvin, and Rankine. Follow this step-by-step tutorial and create your own temperature conversion program.

PHP脚本可用于将温度值与摄氏温度,华氏温度,开尔文温度和兰金温度之间进行转换 。 按照此分步教程并创建自己的温度转换程序。

设置表格 ( Setting Up the Form )

The first step in creating an online temperature conversion program is to collect the data from the user. In this case, the form collects the degrees and the units the degrees are measured in. You are using a drop-down menu for the units and giving them four options. This form uses the ​​$_SERVER[’PHP_SELF’] command to indicate it sends the data back to itself.

创建在线温度转换程序的第一步是从用户那里收集数据。 在这种情况下, 表单将收集度数和度数的度量单位。您将使用一个下拉菜单作为单位,并为它们提供四个选项。 这种形式使用$ _SERVER [“PHP_SELF”]命令,以指示其发送数据返回给自身。

Put the code below into a file called convert.php

将下面的代码放入一个名为convert.php的文件中

使用IF进行转换 ( Using IF for Conversions )

If you recall, the form is sending data back to itself. This means that all of your PHP will be contained in the same file you placed your form in. Continuing to work in the convert.php file, place this PHP code under the HTML you entered in the last step.

如果您还记得,该表单会将数据发送回自身。 这意味着您所有PHP都将包含在您放置表单的同一个文件中。继续在convert.php文件中工作,请将此PHP代码放置在上一步中输入的HTML下。

This code converts a Celcius temperature to Fahrenheit, Kelvin, and Rankine and then prints their values in a table below the original form. The form is still at the top of the page and is ready to accept new data. Currently, if the data is anything but Celcius it will be ignored. In the next step, you will add in the other conversions so options other than Celcius work.

此代码将摄氏温度转换为华氏度 ,开尔文和朗肯,然后将其值打印在原始表格下方的表格中。 该表格仍位于页面顶部,可以接受新数据。 当前,如果数据不是Celcius,它将被忽略。 在下一步中,您将添加其他转换,以便使用除Celcius之外的其他选项。

增加更多转化 ( Adding More Conversions )

Still working in the convert.php file, add the following code at the end of the document, just before the ?> end PHP tag.

仍在convert.php文件中工作,在文档末尾的?> end PHP标记之前添加以下代码。

and put this code after the ?> closing PHP tag to close up the HTML

并将此代码放在?>关闭PHP标记后以关闭HTML

脚本解释 ( The Script Explained )

First, the script collects data from the user and then submits this information to itself. When the page reloads after hitting submit, the PHP at the bottom now has variables to work with and can execute.

首先,脚本从用户收集数据,然后将此信息提交给自己。 点击提交后页面重新加载时,底部PHP现在具有可以使用并可以执行的变量。

Your convert temperature PHP consists of four IF statements, one for each of the unit measurements available on our form. The PHP then makes the appropriate conversions based on the users choice and outputs a table. The complete code for this script can be downloaded from GitHub.

您的换算温度PHP由四个IF语句组成,一个用于我们表格上可用的每个单位度量。 然后,PHP根据用户的选择进行适当的转换并输出一个表。 可以从GitHub下载此脚本的完整代码。

翻译自: https://www.thoughtco.com/convert-temperature-2693992

markdown转换脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值