LoginSignup
0
1

More than 5 years have passed since last update.

PHP 電卓作成

Posted at

■入力画面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xm1ns="http://www.w3.org/1999/xhtml">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">


    <title>PHP入門</title>

</head>
<body>

    <form action="test05_output.php" method="post">
        <p>
            <textarea rows="1" cols="2" name="area1"></textarea>
            +<input type="radio" name="calculate" value="plus"> -<input
                type="radio" name="calculate" value="minus"> ÷<input type="radio"
                    name="calculate" value="divide"> ×<input type="radio"
                        name="calculate" value="multiply">

            <textarea rows="1" cols="2" name="area2"></textarea>

        </p>

        <input type="submit" value="送信">

</body>
</html>

■結果画面

<?php
$area1 = $_POST ["area1"];
$area2 = $_POST ["area2"];
$calculation = $_POST ["calculate"];
switch ($calculation) {
    case "plus" :
        $calculation = $area1 + $area2;
        break;
    case "minus" :
        $calculation = $area1 - $area2;
        break;
    case "divide" :
        $calculation = $area1 / $area2;
        break;
    default :
        $calculation = $area1 * $area2;
        break;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xm1ns="http://www.w3.org/1999/xhtml">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">


    <title>PHP入門</title>

</head>
<body>
<?php echo $calculation;?>

</body>
</html>

■実行結果
電卓input.png
電卓output.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1