Php 计算圆
我这样做了,但是当我试图在InternetExplorer上查看PHP部分时,我看不到它 这是我做的代码:Php 计算圆,php,geometry,Php,Geometry,我这样做了,但是当我试图在InternetExplorer上查看PHP部分时,我看不到它 这是我做的代码: <html> <head><title>Practise</title></head> <body> <form method="post"> Circumference of a Circle or the Area: <br> The Radius of the circle: <
<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="radius"><br>
<input type="submit" value="Submit">
<?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.;
?>
</body>
</html>
实践
圆或面积的周长:
圆的半径:
请说出错误的代码。谢谢大家! 两条回波线应为:
echo "The circumference of the circle is:".$cir;
echo "The area of the circle is:".$area;
连接运算符(点)位于要合并的字符串之间
由于语法错误,当前代码未执行。这样更好:
...
<form method="post" action="this-page.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" />
</form>
<?php
if (array_key_exists("radius", $_POST)) {
$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.";
}
?>
...
。。。
圆或面积的周长:
圆的半径:
...
首先,字符串连接错误:
$result = "String " $var.; // Wrong
$result = "String " . $var; // Right
$result = "String $var"; // Right too.
$result = "String ", $var; // Also right.
然后,您应该真正执行一些输入检查:
if (!empty($_POST['radius']) {
// ...
}
还有一个关闭的
标记丢失,以及
标记上的action=“…”
属性,尽管这应该默认为页面本身
最后是“实践”,而不是“实践”…) 你的回声被破坏了:
echo 'The circumference of the circle is:'.$cir.'.';
echo 'The area of the circle is:'.$area.'.';
@江户:请编辑你的问题,粘贴真实代码,选择它,然后点击编辑器中的
{}
按钮。它将生成可读的代码和html。除了额外的参数(还有,在我看来,使用PHP的字符串扩展和使用isset()而不是array_key_exists()--这些参数是离题的)之外,为什么要“实践”呢?“实践”(名词)和“实践”(动词)都是正确的<代码>缺失,表单的操作
属性缺失。至于显示字符串,echo“string”,$var代码>也可以使用。不知道第三种形式。在中编辑您的评论。@Edo:太好了!你可能想接受我的回答(或者passcod的,或者John Green的——他们都解决了相同的问题)。