diff --git a/Conversions/length-converter.php b/Conversions/length-converter.php new file mode 100644 index 0000000..c07f544 --- /dev/null +++ b/Conversions/length-converter.php @@ -0,0 +1,114 @@ + 1, + 'kilometers' => 1000, + 'feet' => 0.3048, + 'miles' => 1609.34, + ]; + + // Convert input value to meters + $valueInMeters = $value * $conversionRates[$fromUnit]; + + // Convert meters to the desired unit + return $valueInMeters / $conversionRates[$toUnit]; +} + +// Initialize variables +$result = null; +$error = null; + +// Check if the form is submitted +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $value = $_POST['value']; + $fromUnit = $_POST['fromUnit']; + $toUnit = $_POST['toUnit']; + + // Validate input + if (is_numeric($value) && $value >= 0) { + // Perform the conversion + $result = convertLength($value, $fromUnit, $toUnit); + } else { + $error = "Please enter a valid positive number."; + } +} +?> + + + + + + + Length Unit Converter + + + +
+

Length Unit Converter

+
+ + + + +
+ + +

Result:

+ +

+ +
+ +