Convert From Feet to Yards Using PHP Script Code With HTML

Hello Friends Today, through this tutorial, I will tell you How can i Convert From Feet to Yards Using PHP Script Code With HTML.

Certainly! Here’s a simple PHP script with HTML to convert feet to yards:

feettoyards.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Feet to Yards Converter</title>
</head>
<body>
<h2>Feet to Yards Converter</h2>
<?php
// Function to convert feet to yards
function feetToYards($feet) {
return $feet / 3.0;
}
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$feet = isset($_POST["feet"]) ? floatval($_POST["feet"]) : 0;
$yards = feetToYards($feet);
echo "<p>$feet feet is equal to $yards yards.</p>";
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="feet">Enter feet:</label>
<input type="number" step="any" name="feet" required>
<button type="submit">Convert</button>
</form>
</body>
</html>

This script includes a simple HTML form with a text input for entering feet. Upon submitting the form, the PHP script calculates the equivalent yards and displays the result on the page. The `feetToYards` function is responsible for the conversion.