Hello Friends Today, through this tutorial, I will tell you Convert from Inches to Kilometers php script code with html.
Here’s how to convert inches to kilometers using PHP with HTML:
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Inches to Kilometers Converter</title> </head> <body> <h1>Inches to Kilometers Converter</h1> <form action="converter.php" method="post"> <label for="inches">Enter value in Inches:</label> <input type="number" name="inches" id="inches" required> <br> <input type="submit" value="Convert"> </form> </body> </html>
converter.php
<?php // Get the input value from the form if ($_SERVER['REQUEST_METHOD'] === 'POST') { $inches = $_POST['inches']; } else { // Handle potential errors or display a message if no value is submitted echo "Please enter a value in inches."; exit; } // Conversion factor: 1 inch = 0.0000254 kilometers $kilometers = $inches * 0.0000254; // Display the result echo "<h2>Result</h2>"; echo "<p>$inches inches is equal to $kilometers kilometers.</p>"; ?>
Explanation:-
1. index.html:- This file creates a simple form with a label and an input field for entering the value in inches. It also includes a submit button.
2. converter.php:- This file processes the form submission.
– It checks if the request method is POST, meaning the form was submitted.
– If the method is POST, it retrieves the value from the `inches` input field using `$_POST[‘inches’]`.
– It performs the conversion using the formula `$kilometers = $inches * 0.0000254`.
– Finally, it displays the result using HTML elements.
Running the code:-
1. Save the above code as two separate files: `index.html` and `converter.php`.
2. Place both files in the same directory on a web server with PHP enabled.
3. Open the `index.html` file in your web browser.
4. Enter a value in inches and click the “Convert” button.
5. The page will display the converted value in kilometers.