webかたつむり ウェブデザインを勉強中 ウェブ初心者のおぼえがき

webかたつむり

WEB制作会社のフォトグラファー

php BMI 判定プログラム テキスト課題

  • 'm' to the 'n'th power→mのn乗
  • pow(m,n);

f:id:ohta-felica:20160718221338p:plain

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無題ドキュメント</title>
</head>

<body>
<?php
if(isset($_GET['weight']) && isset($_GET['height'])){
$weight=$_GET['weight'];
$weight=floatval($weight);
$height=$_GET['height'];
$height=floatval($height);
$bmi=$weight/pow(($height/100),2);
$bmi=round($bmi);
if($bmi<=25){
echo 'あなたのBMIは'.$bmi.'です。正常値です';
}else{
echo 'あなたのBMIは'.$bmi.'です。健康に気をつけましょう';
}
}else{
$self=$_SERVER['SCRIPT_NAME'];
echo '<form action="'.$self.'" method="get">';
echo '<p>あなたの体重を入力してください。(半角数字)<input type="text" name="weight"></p>';
echo '<p>あなたの身長を入力してください。(半角数字)<input type="text" name="height"></p>';
echo '<p><input type="submit" value="判定する"></p>';
}
?>
</body>
</html>