Convert From Feet to CM Using PHP Script Code With HTML

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

Here’s the HTML and PHP code for a Feet to cm converter:


<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Feet to Centimeters Converter</title>
<h1>Feet to Centimeters Converter</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="feet">Enter value in feet:</label>
<input type="number" name="feet" id="feet" required>
<button type="submit">Convert</button>
// Conversion factor
$conversion_rate = 30.48;
// Check if form is submitted
if (isset($_POST['feet'])) {
$feet = (float) $_POST['feet'];
$converted_cm = $feet * $conversion_rate;
<?php if (isset($_POST['feet'])): ?>
<p><b><?php echo $_POST['feet']; ?> feet is equal to <?php echo $converted_cm; ?> centimeters.</b></p>
<?php endif; ?>


1. Defines the basic structure with heading, form, and result display area.
2. Uses a form to submit the value entered for feet.
3. Checks if `$_POST[‘feet’]` is set in the PHP code to display the result only after conversion.

1. Defines the conversion rate (1 foot equals 30.48 centimeters).
2. Checks if the form is submitted using `isset($_POST[‘feet’])`.
3. Retrieves the entered value and converts it to centimeters.
4. Displays the converted value using string interpolation within the HTML code.

This code utilizes a simple form with PHP to perform the conversion and display the result within the HTML page.