sincostan.php
程式码如下:
<!doctype html>
<html>
<head>
<style>
.press { width:162px; }
.error { color:#F00; }
</style>
<meta charset="utf-8">
<title>三角函数</title>
</head>
<body>
<?php
$scaleErr="";
settype($scale,"double"); //scale变成double型态
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["scale"])) {
$scaleErr = "忘了写倍数了";
}
else {
$scale=test_input($_POST["scale"]);
$scale=$scale*pi();
//倍数可以是小数或整数
}
}
function test_input($data) {
if(!is_string($data)) $data='scale';
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]);?>">
请输入倍数:<input type="text" name="scale" class="press">
<span class="error">* <?php echo $scaleErr;?></span>
<br><br><input type="submit" name="submit" value="送出"><br>
</form>
<?php
if($scale!=0){
echo "<br>";
echo "sin(".$scale.")=".sin($scale)."<br>";
echo "cos(".$scale.")=".cos($scale)."<br>";
echo "tan(".$scale.")=".tan($scale)."<br>";
echo "cot(".$scale.")=".(1/tan($scale))."<br>";
echo "sec(".$scale.")=".(1/cos($scale))."<br>";
echo "csc(".$scale.")=".(1/sin($scale))."<br>";
}
else {
$scale=@($scale==0);
echo "$php_errormsg";
}
?>
</body>
</html>
假设我倍数输入0.666666666666666
结果如下:
sin(2.09439510239)=0.866025403784
cos(2.09439510239)=-0.5
tan(2.09439510239)=-1.73205080757
cot(2.09439510239)=-0.57735026919
sec(2.09439510239)=-2
csc(2.09439510239)=1.15470053838
结果正确
可是我输入0
结果是* 忘了写倍数了
拜托各位看看哪里有问题
感激不尽