Beispiel #1
0
<?php

require_once 'includes/functions.php';
$from_value = '';
$from_unit = '';
$to_unit = '';
$to_value = '';
if ($_POST['submit']) {
    $from_value = $_POST['from_value'];
    $from_unit = $_POST['from_unit'];
    $to_unit = $_POST['to_unit'];
    $to_value = convert_length($from_value, $from_unit, $to_unit);
}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Convert Length</title>
    <link href="styles.css" rel="stylesheet" type="text/css">
  </head>
  <body>

    <div id="main-content">

      <h1>Convert Length</h1>
  
      <form action="" method="post">
        
        <div class="entry">
          <label>From:</label>&nbsp;
function convert_speed($value, $from_unit, $to_unit)
{
    // Adding some if statements so our explode() works as it is
    if ($from_unit == "knots") {
        $from_unit = "nautical_miles_per_hour";
    }
    if ($to_unit == "knots") {
        $to_unit = "nautical_miles_per_hour";
    }
    list($from_dist, $from_time) = array_pad(explode("_per_", $from_unit), 2, null);
    // array_pad() is used to remove a "Notice: undefined offset 1"
    list($to_dist, $to_time) = array_pad(explode("_per_", $to_unit), 2, null);
    // array_pad() is used to remove a "Notice: undefined offset 1"
    if ($from_time == "hour") {
        $value = $value / 3600;
        // 1 hour divided by 3600 seconds (1h = 3600s)
    }
    $value = convert_length($value, $from_dist, $to_dist);
    // Using our already created function
    if ($to_time == "hour") {
        $value = $value * 3600;
    }
    return $value;
}
Beispiel #3
0
function convert_speed($value, $from_unit, $to_unit)
{
    if ($from_unit == 'knots') {
        $from_unit = 'nautical_miles_per_hour';
    }
    if ($to_unit == 'knots') {
        $to_unit = 'nautical_miles_per_hour';
    }
    list($from_dist, $from_time) = explode('_per_', $from_unit);
    list($to_dist, $to_time) = explode('_per_', $to_unit);
    if ($from_time == 'hour') {
        $value /= 3600;
    }
    $value = convert_length($value, $from_dist, $to_dist);
    if ($to_time == 'hour') {
        $value *= 3600;
    }
    return $value;
}
Beispiel #4
0
function convert_speed($value, $from_unit, $to_unit)
{
    list($from_dist, $from_time) = explode('_per_', $from_unit);
    list($to_dist, $to_time) = explode('_per_', $to_unit);
    if ($from_time == 'hour') {
        $value /= 3600;
    }
    $value = convert_length($value, $from_dist, $to_dist);
    if ($to_time == 'hour') {
        $value *= 3600;
    }
    return $value;
}