Skip to content

Instantly share code, notes, and snippets.

@cloneko
Forked from KimiyukiYamauchi/bmi.php
Last active December 28, 2015 05:38
Show Gist options
  • Save cloneko/7450721 to your computer and use it in GitHub Desktop.
Save cloneko/7450721 to your computer and use it in GitHub Desktop.
<?php
function bmi ($height,$mass){
return $mass / pow($height/100,2);
}
function h($str) {
return htmlspecialchars($str, ENT_QUOTES, "UTF-8");
}
?>
<!DOCTYPE html>
<html>
<head>
<style>
#over{
color: red;
display: inline;
}
#slim{
color: blue;
display: inline;
}
#standard{
color: black;
display: inline;
}
</style>
</head>
<body>
<?php
if (isset($_POST["submit"])) {
$bmi = bmi($_POST["height"], $_POST["mass"]);
$bmi = round($bmi, 1);
print "あなたの BMI 値は" . h($bmi) . "です ";
} else {
print "BMI 値を計算します ";
}
?>
<form action="<?php print($_SERVER['REQUEST_URI']); ?>" method="POST">
身長 <br>
<input type="text" name="height"><br>
体重 <br>
<input type="text" name="mass"><br>
<input type="submit" name="submit" value=" 送信 "><br>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment