Home >>PHP Programs >PHP Program to find the area of a given triangle
In this example, we will create a PHP program to find the area of a given triangle.
The Mathematical formula to calculate the Area of a triangle is,
Area = (base * height) / 2
<?php
$base = 15;
$height = 25;
echo "area with base $base and height $height= " . ($base * $height) / 2;
?>
<?php
extract($_REQUEST);
if(isset($calculate))
{
echo "area with base $base and height $height= " . ($base * $height) / 2;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Form</title>
</head>
<body>
<form method="post">
<table>
<tr>
<td>Enter Your Base</td>
<td><input type="text" name="base" required/></td>
</tr>
<tr>
<td>Enter Your Height</td>
<td><input type="text" name="height" required/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Calculate Aread" name="calculate"/>
</tr>
</form>
</body>
</html>