Convert from Kilometers to Yards PHP Script Code With HTML

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

Here’s the PHP script with HTML for converting kilometers to yards:

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kilometers to Yards Converter</title>
<h1>Kilometers to Yards Converter</h1>
// Define conversion rate
$conversion_rate = 1093.61;
// Check if form is submitted
// Get the value from the form
$kilometers = (float) $_POST['kilometers'];
// Perform conversion
$yards = $kilometers * $conversion_rate;
// Display the result
echo "<p><b>$kilometers kilometers is equal to $yards yards.</b></p>";
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="kilometers">Enter kilometers:</label>
<input type="number" name="kilometers" id="kilometers" required>
<button type="submit">Convert</button>

This code simplifies the process by directly defining the conversion rate and using a shorter approach to handle form submission. It also uses `htmlspecialchars` to prevent XSS vulnerabilities in the form action.