This PHP script calculates Body Mass Index (BMI); it uses a simple calculation to measure the amount of body fat based on a person's weight and height.

PHP BMI Calculator Program Demo

PHP Program to Calculate BMI

        if($Height == '' || $Weight == '' || $HeightUnit == '' || $WeightUnit == ''){
                $Error = "The input values are required.";
        elseif (filter_var($Height, FILTER_VALIDATE_FLOAT) === false || filter_var($Weight, FILTER_VALIDATE_FLOAT) === false) {
                $Error = "The input value must be a number only.";
                /*Calculation begins from here.*/
                /*Convert cm to inch -> foot to inch -> meter to inch */
                $HInches = ($HeightUnit=='centimeter')?$Height*0.393701:(($HeightUnit=='foot')?$Height*12:(($HeightUnit=='meter')?$Height*39.3700787:$Height));
                /*Convert kg to pound*/
                $WPound = ($WeightUnit=='kilogram')?$Weight*2.2:$Weight;
                $BMIIndex = round($WPound/($HInches*$HInches)* 703,2);

                /*Set Message*/
                if ($BMIIndex < 18.5) {
                } else if ($BMIIndex <= 24.9) {
                } else if ($BMIIndex <= 29.9) {
                } else {
} ?>

What Is Body Mass Index (BMI)

Body mass index is called BMI, which measures the amount of body fat based on a person's weight and height. As per the WHO (World Health Organization), The standard BMI value is 18.5 to 24.9; If BMI falls in this range, a person's body height and weight ratio are considered healthy. A BMI less than 18.5 indicates a very skinny and underweight person who needs to increase their calorie and carbohydrate content. A BMI greater than 25 to 29.9 indicates that the person is overweight. A BMI above the range of 30 is considered very dangerous. And such a person can be classified as obese.

BMI Formulas

This BMI calculator uses the formula below to calculate the BMI:

  1. Metric units: BMI = weight (kg) / height2 (meters)
  2. US units: BMI = [weight (pound) / height2 (inches) ]* 703


For example, a person's weight is 45 kg, and his height is 66 inches. So let's know what his BMI is?

Height: 66 inches = 1.6764 meters
Square of height: (1.6764 * 1.6764) m2 = 2.81 m2
Weight: 45 kilograms
BMI = 45/2.81 = 16
PHP Syntax:
echo round($weight/($height*$height)* 703,2) /*US units: BMI*/

This BMI calculator is not clinical guidance nor a substitute for professional medical advice. Since BMI depends on weight and height, it is only an indicator of body obesity. The amount of fat in individuals with the same BMI may vary. Individuals may consider seeking advice from their healthcare providers.