Hello Friends Today, through this tutorial, I will tell you Convert from Kilometers to centimeters php script code with html.
Here’s the PHP script with HTML for converting kilometers to centimeters:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Kilometers to Centimeters Converter</title> </head> <body> <h1>Kilometers to Centimeters Converter</h1> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> <label for="kilometers">Enter kilometers:</label> <input type="number" name="kilometers" id="kilometers" required> <br> <button type="submit" name="submit">Convert</button> </form> <?php // Check if form is submitted if (isset($_POST['submit'])) { // Get the kilometers value $kilometers = (float) $_POST['kilometers']; // Conversion rate: 1 kilometer = 100,000 centimeters $conversion_rate = 100000; // Calculate centimeters $centimeters = $kilometers * $conversion_rate; // Display the result echo "<p><b>$kilometers kilometers is equal to $centimeters centimeters.</b></p>"; } ?> </body> </html>
This code simplifies the conversion by directly using the conversion rate (1 kilometer = 100,000 centimeters) within the script. It avoids defining multiple units and conversion rates as in the previous example.