使用html和php计算圆
提前致谢!
只是想问如何使用 html 和 php 计算圆的周长和面积
我的代码是这样的
<html>
<head><title>Practise</title></head>
<body>
<form method=post>
Circumference of a Circle or the Area <br>
The Radius of the circle: <input type="text" name="num1"><br>
<input type="submit" value="Submit"></form><hr>
<?php
$num=$_POST["3.14"]*$_POST["num1"];
echo "The Circuference of the circle is $num<br>";
?>
<hr>
</body>
</html>
编辑:
感谢您的答案!所以我这样做了,但当我尝试在 Internet Explorer 上查看 php 时,我看不到它。
这是我所做的代码:
Circumference of a Circle or the Area: <br>
The Radius of the circle: <input type="text" name="radius"> <br>
<input type="submit" value="Submit"> <hr>
<?php
$rad = (float) $_POST['radius'];
$cir = $rad * 2 * pi();
$area = pow($rad, 2) * pi();
echo "The circumference of the circle is:" $cir.;
echo "The area of the circle is:" $area.;
?>
它似乎仍然不起作用,我错过了什么?
Thanks in advance!
Just want to ask how to calculate the circumference and the area of a circle using html and php
my code is something like this
<html>
<head><title>Practise</title></head>
<body>
<form method=post>
Circumference of a Circle or the Area <br>
The Radius of the circle: <input type="text" name="num1"><br>
<input type="submit" value="Submit"></form><hr>
<?php
$num=$_POST["3.14"]*$_POST["num1"];
echo "The Circuference of the circle is $num<br>";
?>
<hr>
</body>
</html>
EDIT:
Thanks for the answers!!! so I did this but I can't see the php one when I tried to view it on Internet Explorer.
This is the code I did:
Circumference of a Circle or the Area: <br>
The Radius of the circle: <input type="text" name="radius"> <br>
<input type="submit" value="Submit"> <hr>
<?php
$rad = (float) $_POST['radius'];
$cir = $rad * 2 * pi();
$area = pow($rad, 2) * pi();
echo "The circumference of the circle is:" $cir.;
echo "The area of the circle is:" $area.;
?>
It still doesn't seem to work though, what am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为应该是 应该
有效,因为帖子正在获取变量 3.14 不会像你的帖子那样工作。正如我所期望的那样,num1 是半径,如果 num1 还不是直径(2r),则周长计算需要 2 的倍数。
I think it should have been
That should work, since post is getting variable 3.14 won't work as your post. num1 as I expect is radius and multiple of 2 is required for circumference calculation for the case if num1 is not already diameter(2r).
pi 已经是 PHP 中的常量,因此无需指定 $pi
代码可以简化为:
pi is already a constant in PHP so there is no need to specify $pi
the code can be reduced to this:
POST 数组中的数组元素指的是发布到 PHP 页面的字段。在 HTML 中,确保有一个名为“radius”的文本输入,并将以下代码放入 PHP 页面中:
回想一下,圆的面积要求您知道半径,A(r) = π r^2。接下来,圆周将为 C(r) = 2πr。代码就是这样做的,现在 $cir 应该保存周长,$area 应该保存面积。
The array element in the POST array refers to the field that was posted to PHP page. In your HTML, make sure you have a text input called "radius" and put the following code in your PHP page:
Recall the area for a circle requires that you know the radius, A(r) = π r^2. Next, the circumfrence would be C(r) = 2πr. The code does just that, and now $cir should hold the circumference, $area should hold the area.