- 九宫格
代码
echo <<<EOF
<table border="1" cellspacing="0" cellspadding="0">
<tr>
<td bgcolor="red">1</td>
<td bgcolor="yellow">2</td>
<td bgcolor="blue">3</td>
</tr>
<tr>
<td bgcolor="green">4</td>
<td bgcolor="orange">5</td>
<td bgcolor="pink">6</td>
</tr>
<tr>
<td bgcolor="whtie">7</td>
<td bgcolor="violet">8</td>
<td bgcolor="coral">9</td>
</tr>
</table>
EOF;
2.简易计算器
代码
echo <<<EOF
<form action="" method="get">
<input type="number" name="num1">
<select name="select">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
<option value="%">%</option>
</select>
<input type="number" name="num2">
<button type="submit">=</button>
</form>
EOF;
$num1 = (int)$_GET["num1"];
$num2 = (int)$_GET["num2"];
$select = $_GET["select"];
$new;
switch ($select) {
case "+":
echo $new = $num1 + $num2;
break;
case "-":
echo $new = $num1 - $num2;
break;
case"*":
echo $new = $num1 * $num2;
break;
case"/":
if ($num2 == 0) {
echo "<script>alert('0不能作为除数')</script>";
}
else{
echo $new = $num1 / $num2;
}
break;
case"%":
if ($num2 == 0) {
echo "<script>alert('0不能作为除数')</script>";
}
else{
echo $new = $num1 % $num2;
}
break;
}