How to Create Kilometers to Feet Converter Tool Using PHP With HTML Code?

Hello Friends Today, through this tutorial, I will tell you How to Create Kilometers to Feet Converter Tool Using PHP With HTML Code?.

Here’s the PHP script with HTML code to convert from Kilometers to Feet:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kilometers to Feet Converter</title>
</head>
<body>
<h1>Kilometers to Feet Converter</h1>
<?php
// Check if form is submitted
if (isset($_POST['submit'])) {
$km = (float) $_POST['km'];
// Conversion rate: 1 kilometer = 3280.84 feet
$feet = $km * 3280.84;
echo "<p><b>$km kilometers is equal to $feet feet.</b></p>";
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="km">Enter kilometers:</label>
<input type="number" name="km" id="km" required>
<br>
<button type="submit" name="submit">Convert</button>
</form>
</body>
</html>

This code defines a simple HTML form with a label and input field for entering the kilometers. When the form is submitted, the script:

1. Retrieves the entered kilometers using `$_POST[‘km’]`.
2. Converts the kilometers to feet using the conversion rate (1 kilometer = 3280.84 feet).
3. Displays the converted value in a paragraph element.