【发布时间】:2016-03-01 03:10:34
【问题描述】:
(第一次发帖,如果格式不好,请见谅:()
我拼凑了一个 html/php 页面。它适用于我使用 phpfiddle.org 的现场测试环境
Working there it looks like this
当我保存代码并将文件上传到我的服务器时(我尝试了两台服务器,两者都存在同样的问题),it's broken
我怀疑问题可能出在标题上,但我不知道。
这是我的代码:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
$potErr = $stackErr = "";
$pot = $stack = "";
$p = $s = $g1 = $g2 = $b11 = $b12 = $b21 = $b22 = $b23 = 0;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["pot"])) {
$potErr = "Pot size is required";
} else {
$pot = test_input($_POST["pot"]);
if (!preg_match("/^\d+$/",$pot)) {
$potErr = "Only integers allowed (might work with decimals though, I haven't tested it')";
}
}
if (empty($_POST["stack"])) {
$stackErr = "Stacksize is required";
} else {
$stack = test_input($_POST["stack"]);
if (!preg_match("/^\d+$/",$pot)) {
$stackErr = "Only integers allowed";
}
}
$p = $pot;
$s = $stack;
$g1 = pow(($p+2*$s)/$p,1/2);
$g2 = pow(($p+2*$s)/$p,1/3);
$b11 = ($p*$g1-$p)/2;
$b21 = ($p*$g2-$p)/2;
$b12 = $p*$g1*($g1-1)/2;
$b22 = $p*$g2*($g2-1)/2;
$b23 = $p*$g2*$g2*($g2-1)/2;
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>Geometric Sizing Calculator</h2>
<p>
<i>Shoutout to AlexMartin's pokernerdz.com which is unfortunately offline. A quick geo calc in his honor! - Paul lnternet Otto </i>
</p>
<p><span class="error">* required field.</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Pot: <input type="text" name="pot" value="<?php echo $pot;?>">
<span class="error">* <?php echo $potErr;?></span>
<br><br>
Stack: <input type="text" name="stack" value="<?php echo $stack;?>">
<span class="error">* <?php echo $stackErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo "<h2>Geo Sizing:</h2>";
echo "<b>2-street sizing plan:</b> <br>";
echo "Bet " . round($b11) . " then bet " . round($b12) .".";
echo "<br><br>";
echo "<b>3-street sizing plan:</b> <br>";
echo "Bet " . round($b21) . " then bet " . round($b22) . " then bet " . round($b23) .".";
?>
</body>
</html>
【问题讨论】:
-
格式化不仅仅是有点糟糕。
-
我可以在这里运行sn-p,它有同样的错误。太棒了:D
-
@chris85 我保存为.html
-
@frosty 我把代码放在这里,也许更好pastebin.com/8qm5EbzK
-
另外
^\d+$说只允许数字;没有小数。另外还有一个内置函数is_numeric和c_digit来检查输入是否为整数。