How to Convert Inches to Feet Using PHP With HTML?

Hello Friends Today, through this tutorial, I will tell you Convert from Inches to Feet php script code with html.

Here’s how to convert inches to feet using PHP with HTML:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Inches to Feet Converter</title>
</head>
<body>
<h1>Inches to Feet Converter</h1>
<form action="converter.php" method="post">
<label for="inches">Enter value in Inches:</label>
<input type="number" name="inches" id="inches" required>
<br>
<input type="submit" value="Convert">
</form>
</body>
</html>

converter.php.

<?php
// Get the input value from the form
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$inches = $_POST['inches'];
} else {
// Handle potential errors or display a message if no value is submitted
echo "Please enter a value in inches.";
exit;
}
// Conversion:
// 1. Calculate the number of feet
$feet = floor($inches / 12); // Use floor function to discard any remainder (decimal part)
// 2. Calculate the remaining inches
$remainingInches = $inches % 12; // Use modulo operator (%) to get the remainder
// Display the result
echo "<h2>Result</h2>";
// Check if there are only feet or both feet and inches
if ($remainingInches === 0) {
echo "<p>$inches inches is equal to $feet feet.</p>";
} else {
echo "<p>$inches inches is equal to $feet feet and $remainingInches inches.</p>";
}
?>