计算一个圆

发布于 2024-11-08 20:16:32 字数 644 浏览 0 评论 0原文

我这样做了,但当我尝试在 Internet Explorer 上查看 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="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>

请指出错误的代码。谢谢你!

I did this but I can't see the PHP part when I tried to view it on Internet Explorer.

This is the code I did:

<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>

Please state the wrong code. Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深府石板幽径 2024-11-15 20:16:32

两条回显线应该是:

echo "The circumference of the circle is:".$cir; 
echo "The area of the circle is:".$area; 

连接运算符(点)位于要合并的字符串之间。

由于语法错误,您当前的代码未执行。

The two echo lines should be:

echo "The circumference of the circle is:".$cir; 
echo "The area of the circle is:".$area; 

The concatenation operator (point) goes between the strings you want to merge.

Your current code isn't executed because of a syntax error.

心如狂蝶 2024-11-15 20:16:32

好吧,首先你的字符串连接错误:

$result = "String " $var.;  // Wrong
$result = "String " . $var; // Right
$result = "String $var";    // Right too.
$result = "String ", $var;  // Also right.

然后你真的应该做一些输入检查:

if (!empty($_POST['radius']) {
  // ...
}

还有一个结束 标签丢失,以及 action="..."

标记上的 属性 - 尽管这应该默认为页面本身。

最后是“练习”,而不是“练习”......:)

Well first you got string concatenation wrong:

$result = "String " $var.;  // Wrong
$result = "String " . $var; // Right
$result = "String $var";    // Right too.
$result = "String ", $var;  // Also right.

Then you should really do some input checking:

if (!empty($_POST['radius']) {
  // ...
}

There's also a closing </form> tag missing, as well as the action="..." attribute on the <form> tag -- although this should default to the page itself.

And finally it's 'Practice', not 'Practise'... :)

雨落□心尘 2024-11-15 20:16:32

你的回声被打破了:

echo 'The circumference of the circle is:'.$cir.'.'; 
echo 'The area of the circle is:'.$area.'.';  

Your echos are broken:

echo 'The circumference of the circle is:'.$cir.'.'; 
echo 'The area of the circle is:'.$area.'.';  
云淡风轻 2024-11-15 20:16:32

这是更好的:

...
<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.";
}
?>
...

This is better:

...
<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.";
}
?>
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文