Convertitore unità di misura con il linguaggio PHP

Abbiamo costruito un semplice convertitore di unità di misura con il linguaggio PHP. Lo spunto ci era stato dato da un articolo del nostro laboratorio di fisica in cui si parlava appunto di unità di misura, del Sistema Internazionale di misura, multipli e sottomultipli.

Prerequisiti per le prove di codice

Prima di iniziare, diamo spesso per scontato che chi si imbatte in queste pagine sia pratico di programmazione e sia a conoscenza degli strumenti minimi per poter effettuare delle prove di codice con il linguaggio PHP. A tale proposito ricordiamo che per provare le righe di codice proposte sono necessari i seguenti strumenti software:

  • Browser che utilizzate per navigare (Firefox, Chrome, Opera, Safati, … fate voi)
  • Editor per la scrittura del codice (ad esempio Sublime Text)
  • Web Server installato in locale (ad esempio XAMPP) o servizio web con file da salvare con l’FTP

La pagina principale del convertitore

Partiamo dalla main page, la pagina che chiameremo index.php, che vi indirizzerà alle singole procedure per il calcolo e la conversione tra unità di misura:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Conversione delle unità di misura</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="main-content">
<h1>Conversione delle unità di misura</h1>
<ul id="measurement-types">
<li><a href="lunghezza.php">Lunghezza e Distanza</a></li>
<li><a href="area.php">Area</a></li>
<li><a href="volume.php">Volume e Capacità</a></li>
<li><a href="massa.php">Massa e Peso</a></li>
<li><a href="velocita.php">Velocità</a></li>
<li><a href="temperatura.php">Temperatura</a></li>
</ul>
</div>
</body>
</html>

Il foglio di stile del Convertitore di unità di misura

Immancabile il foglio di stile che potrete integrare nei vostri progetti modificando la grafica in maniera opportuna. Create quindi il file styles.css così come di seguito:

html{
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
body{
height: 100%;
width: 100%;
padding: 0;
background: #EEE;
font: 18px Georgia, Times, "Times New Roman", Serif;
}
#main-content{
width: 500px;
margin: 0 auto; padding: 20px 0;
}
h1{
font: 30px Arial, "Helvetica Neue", Helvetica, Sans-Serif;
}

/*Pagina principale*/
ul#measurement-types{
list-style-type: none;
margin: 1em 0;
padding: 0;
}
ul#measurement-types li{
height: auto;
margin: 0 0 10px 0;
padding: 0;
}
ul#measurement-types li a{
text-decoration: none;
color: black;
display: block;
background: white;
padding: 16px 24px;
width: 180px;
border: 1px solid black;
}
ul#measurement-types li a:hover{
color: white;
background: #FDB912;
}

/*Form per le Conversioni*/
form label{
display: inline-block;
width: 45px;
}
form input[type="text"]{
width: 80px;
font-size: 16px;
line-height: 16px;
}
form select{
margin: 1em 0;
font-size: 14px;
}
form input[type="submit"]{
font-size: 1em;
text-decoration: none;
color: black;
display: block;
background: white;
margin: 2em 0 2em 25px;
padding: 6px 12px;
border: 1px solid black;
}
form input[type="submit"]:hover{
color: white;
background: #FDB912;
}

La pagina functions.php

Rappresenta il vero e proprio elemento principale di tutta la nostra procedura. Quì vengono effettuati i calcoli in base ai dati inviati dalle singole pagine di invio dei dati. Nel vostro progetto create la cartella includes e in quest’ultima inserite la pagine functions.php con il codice che segue:

<?php
const LENGTH_TO_METER = array(
"inches" => 0.0254,
"feet" => 0.3048,
"yards" => 0.9144,
"miles" => 1609.344,
"millimeters" => 0.001,
"centimeters" => 0.01,
"meters" => 1,
"kilometers" => 1000,
"acres" => 63.614907234075,
"hectares" => 100,
"nautical_miles" => 1852
);
const VOLUME_TO_LITER = array(
"cubic_inches" => 0.0163871,
"cubic_feet" => 28.3168,
"cubic_centimeters" => 0.001,
"cubic_meters" => 1000,
"imperial_gallons" => 4.54609,
"imperial_quarts" => 1.13652,
"imperial_pints" => 0.568261,
"imperial_cups" => 0.284131,
"imperial_ounces" => 0.0284131,
"imperial_tablespoons" => 0.0177582,
"imperial_teaspoons" => 0.00591939,
"us_gallons" => 3.78541,
"us_quarts" => 0.946353,
"us_pints" => 0.473176,
"us_cups" => 0.24,
"us_ounces" => 0.0295735,
"us_tablespoons" => 0.0147868,
"us_teaspoons" => 0.00492892,
"liters" => 1,
"milliliters" => 0.001,
); 
const MASS_TO_KILOGRAM = array(
"ounces" => 0.0283495,
"pounds" => 0.453592,
"stones" => 6.35029,
"long_tons" => 1016.05,
"short_tons" => 907.185,
"milligrams" => 0.000001,
"grams" => 0.001,
"kilograms" => 1,
"metric_tonnes" => 1000
);
function optionize($string) {
return str_replace(' ', '_', strtolower($string));
}
function float_to_string($float, $precision=10) {
$float = (float) $float;
$string = number_format($float, $precision, '.', '');
$string = rtrim($string, '0');
$string = rtrim($string, '.');
return $string;
}
// Lunghezza
function convert_to_meters($value, $from_unit) {
if(array_key_exists($from_unit, LENGTH_TO_METER)) {
return $value * LENGTH_TO_METER[$from_unit];
} else {
return "Unità non supportata.";
}
}
function convert_from_meters($value, $to_unit) {
if(array_key_exists($to_unit, LENGTH_TO_METER)) {
return $value / LENGTH_TO_METER[$to_unit];
} else {
return "Unità non supportata.";
}
}
function convert_length($value, $from_unit, $to_unit) {
$meter_value = convert_to_meters($value, $from_unit);
$new_value = convert_from_meters($meter_value, $to_unit);
return $new_value;
}
// Area
function convert_to_square_meters($value, $from_unit) {
$from_unit = str_replace('square_', '', $from_unit);
if(array_key_exists($from_unit, LENGTH_TO_METER)) {
return $value * pow(LENGTH_TO_METER[$from_unit], 2);
} else {
return "Unità non supportata.";
}
}
function convert_from_square_meters($value, $to_unit) {
$to_unit = str_replace('square_', '', $to_unit);
if(array_key_exists($to_unit, LENGTH_TO_METER)) {
return $value / pow(LENGTH_TO_METER[$to_unit], 2);
} else {
return "Unità non supportata.";
}
}
function convert_area($value, $from_unit, $to_unit) {
$meter_value = convert_to_square_meters($value, $from_unit);
$new_value = convert_from_square_meters($meter_value, $to_unit);
return $new_value;
}
// Volume
function convert_to_liters($value, $from_unit) {
if(array_key_exists($from_unit, VOLUME_TO_LITER)) {
return $value * VOLUME_TO_LITER[$from_unit];
} else {
return "Unità non supportata.";
}
}
function convert_from_liters($value, $to_unit) {
if(array_key_exists($to_unit, VOLUME_TO_LITER)) {
return $value / VOLUME_TO_LITER[$to_unit];
} else {
return "Unità non supportata.";
}
}
function convert_volume($value, $from_unit, $to_unit) {
$liter_value = convert_to_liters($value, $from_unit);
$new_value = convert_from_liters($liter_value, $to_unit);
return $new_value;
}
// Massa
function convert_to_kilograms($value, $from_unit) {
if(array_key_exists($from_unit, MASS_TO_KILOGRAM)) {
return $value * MASS_TO_KILOGRAM[$from_unit];
} else {
return "Unità non supportata.";
}
}
function convert_from_kilograms($value, $to_unit) {
if(array_key_exists($to_unit, MASS_TO_KILOGRAM)) {
return $value / MASS_TO_KILOGRAM[$to_unit];
} else {
return "Unità non supportata.";
}
}
function convert_mass($value, $from_unit, $to_unit) {
$kg_value = convert_to_kilograms($value, $from_unit);
$new_value = convert_from_kilograms($kg_value, $to_unit);
return $new_value;
}
// Velocità
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;
}
// Temperatura
function convert_to_celsius($value, $from_unit) {
switch($from_unit) {
case 'celsius':
return $value;
break;
case 'fahrenheit':
return ($value - 32) / 1.8;
break;
case 'kelvin':
return $value - 273.15;
break;
default:
return "Unità non supportata.";
}
}
function convert_from_celsius($value, $to_unit) {
switch($to_unit) {
case 'celsius':
return $value;
break;
case 'fahrenheit':
return ($value * 1.8) + 32;
break;
case 'kelvin':
return $value + 273.15;
break;
default:
return "Unità non supportata.";
}
}
function convert_temperature($value, $from_unit, $to_unit) {
$celsius_value = convert_to_celsius($value, $from_unit);
$new_value = convert_from_celsius($celsius_value, $to_unit);
return $new_value;
}
?>

Area.php

La pagina area.php come le altre che elaborano le conversioni ha bisogno della pagina functions.php per l’elaborazione dei calcoli necessari per le conversioni. Costruite dunque la pagina area.php con il codice che vi proponiamo:

<?php
require_once('includes/functions.php');
$from_value = '';
$from_unit = '';
$to_unit = '';
$to_value = '';
if(isset($_POST['submit'])) {
$from_value = $_POST['from_value'];
$from_unit = $_POST['from_unit'];
$to_unit = $_POST['to_unit'];

$to_value = convert_area($from_value, $from_unit, $to_unit);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Converti Area</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main-content">
<h1>Converti Area</h1>
<form action="" method="post">
<div class="entry">
<label>Da:</label>&nbsp;
<input type="text" name="from_value" value="<?php echo $from_value; ?>" />&nbsp;
<select name="from_unit">
<option value="square_inches"<?php if($from_unit == 'square_inches') { echo " selected"; } ?>>pollici quadri</option>
<option value="square_feet"<?php if($from_unit == 'square_feet') { echo " selected"; } ?>>piedi quadri</option>
<option value="square_yards"<?php if($from_unit == 'square_yards') { echo " selected"; } ?>>yarde quadre</option>
<option value="square_miles"<?php if($from_unit == 'square_miles') { echo " selected"; } ?>>miglia quadre</option>
<option value="square_millimeters"<?php if($from_unit == 'square_millimeters') { echo " selected"; } ?>>square millimeters</option>
<option value="square_centimeters"<?php if($from_unit == 'square_centimeters') { echo " selected"; } ?>>square centimeters</option>
<option value="square_meters"<?php if($from_unit == 'square_meters') { echo " selected"; } ?>>square meters</option>
<option value="square_kilometers"<?php if($from_unit == 'square_kilometers') { echo " selected"; } ?>>square kilometers</option>
<option value="acres"<?php if($from_unit == 'acres') { echo " selected"; } ?>>acri</option>
<option value="hectares"<?php if($from_unit == 'hectares') { echo " selected"; } ?>>ettari</option>
</select>
</div>
<div class="entry">
<label>A:</label>&nbsp;
<input type="text" name="to_value" value="<?php echo float_to_string($to_value); ?>" />&nbsp;
<select name="to_unit">
<option value="square_inches"<?php if($to_unit == 'square_inches') { echo " selected"; } ?>>pollici quadri</option>
<option value="square_feet"<?php if($to_unit == 'square_feet') { echo " selected"; } ?>>piedi quadri</option>
<option value="square_yards"<?php if($to_unit == 'square_yards') { echo " selected"; } ?>>yarde quadre</option>
<option value="square_miles"<?php if($to_unit == 'square_miles') { echo " selected"; } ?>>miglia quadre</option>
<option value="square_millimeters"<?php if($to_unit == 'square_millimeters') { echo " selected"; } ?>>millimetri quadri</option>
<option value="square_centimeters"<?php if($to_unit == 'square_centimeters') { echo " selected"; } ?>>scentimetri quadri</option>
<option value="square_meters"<?php if($to_unit == 'square_meters') { echo " selected"; } ?>>metri quadri</option>
<option value="square_kilometers"<?php if($to_unit == 'square_kilometers') { echo " selected"; } ?>>chilometri quadri</option>
<option value="acres"<?php if($to_unit == 'acres') { echo " selected"; } ?>>acri</option>
<option value="hectares"<?php if($to_unit == 'hectares') { echo " selected"; } ?>>ettari</option>
</select>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
<br />
<a href="index.php">Ritorna al Menù</a>
</div>
</body>
</html>

Lunghezza.php

Allo stesso modo costruite la pagina lunghezza.php con il codice seguente:

<?php
require_once('includes/functions.php');
$from_value = '';
$from_unit = '';
$to_unit = '';
$to_value = '';
if(isset($_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>Convertitore Lunghezza</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main-content">
<h1>Convertitore Lunghezza</h1>
<form action="" method="post">
<div class="entry">
<label>Da:</label>&nbsp;
<input type="text" name="from_value" value="<?php echo $from_value; ?>" />&nbsp;
<select name="from_unit">
<option value="inches"<?php if($from_unit == 'inches') { echo " selected"; } ?>>pollici</option>
<option value="feet"<?php if($from_unit == 'feet') { echo " selected"; } ?>>piedi</option>
<option value="yards"<?php if($from_unit == 'yards') { echo " selected"; } ?>>iarde</option>
<option value="miles"<?php if($from_unit == 'miles') { echo " selected"; } ?>>miglia</option>
<option value="millimeters"<?php if($from_unit == 'millimeters') { echo " selected"; } ?>>millimetri</option>
<option value="centimeters"<?php if($from_unit == 'centimeters') { echo " selected"; } ?>>centimetri</option>
<option value="meters"<?php if($from_unit == 'meters') { echo " selected"; } ?>>metri</option>
<option value="kilometers"<?php if($from_unit == 'kilometers') { echo " selected"; } ?>>chilometri</option>
</select>
</div>
<div class="entry">
<label>A:</label>&nbsp;
<input type="text" name="to_value" value="<?php echo float_to_string($to_value); ?>" />&nbsp;
<select name="to_unit">
<option value="inches"<?php if($to_unit == 'inches') { echo " selected"; } ?>>pollici</option>
<option value="feet"<?php if($to_unit == 'feet') { echo " selected"; } ?>>piedi</option>
<option value="yards"<?php if($to_unit == 'yards') { echo " selected"; } ?>>iarde</option>
<option value="miles"<?php if($to_unit == 'miles') { echo " selected"; } ?>>miglia</option>
<option value="millimeters"<?php if($to_unit == 'millimeters') { echo " selected"; } ?>>millimetri</option>
<option value="centimeters"<?php if($to_unit == 'centimeters') { echo " selected"; } ?>>centimetri</option>
<option value="meters"<?php if($to_unit == 'meters') { echo " selected"; } ?>>metri</option>
<option value="kilometers"<?php if($to_unit == 'kilometers') { echo " selected"; } ?>>chilometri</option>
</select>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
<br />
<a href="index.php">Torna al menù</a>
</div>
</body>
</html>

Massa.php

Anche in questo caso è importante includere la pagina functions.php e il link per il ritorno al Menù principale. Costruite la pagina massa.php con il codice che vi proponiamo:

<?php
require_once('includes/functions.php');
$from_value = '';
$from_unit = '';
$to_unit = '';
$to_value = '';
if(isset($_POST['submit'])) {
$from_value = $_POST['from_value'];
$from_unit = $_POST['from_unit'];
$to_unit = $_POST['to_unit'];
$to_value = convert_mass($from_value, $from_unit, $to_unit);
}
$mass_options = array(
"ounces",
"pounds",
"stones",
"long tons",
"short tons",
"milligrams",
"grams",
"kilograms",
"metric tonnes"
);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Convertitore Massa</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main-content">
<h1>Convertitore Massa</h1>
<form action="" method="post">
<div class="entry">
<label>Da:</label>&nbsp;
<input type="text" name="from_value" value="<?php echo $from_value; ?>" />&nbsp;
<select name="from_unit">
<?php
foreach($mass_options as $unit) {
$opt = optionize($unit);
echo "<option value=\"{$opt}\"";
if($from_unit == $opt) { echo " selezionato"; }
echo ">{$unit}</option>";
}
?>
</select>
</div>
<div class="entry">
<label>A:</label>&nbsp;
<input type="text" name="to_value" value="<?php echo float_to_string($to_value); ?>" />&nbsp;
<select name="to_unit">
<?php
foreach($mass_options as $unit) {
$opt = optionize($unit);
echo "<option value=\"{$opt}\"";
if($to_unit == $opt) { echo " selezionato"; }
echo ">{$unit}</option>";
}
?>
</select>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
<br />
<a href="index.php">Torna al menù</a>
</div>
</body>
</html>

Temperatura.php

Ricordiamo che i gradi Celsius corrispondono ai nostri gradi centigradi, quindi procediamo con la creazione della pagina temperatura.php:

<?php
require_once('includes/functions.php');
$from_value = '';
$from_unit = '';
$to_unit = '';
$to_value = '';
if(isset($_POST['submit'])) {
$from_value = $_POST['from_value'];
$from_unit = $_POST['from_unit'];
$to_unit = $_POST['to_unit'];
$to_value = convert_temperature($from_value, $from_unit, $to_unit);
}
$temp_options = array(
"Celsius",
"Fahrenheit",
"Kelvin"
);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Convertitore di Temperatura</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main-content">
<h1>Convertitore di Temperatura</h1>
<form action="" method="post">
<div class="entry">
<label>Da:</label>&nbsp;
<input type="text" name="from_value" value="<?php echo $from_value; ?>" />&nbsp;
<select name="from_unit">
<?php
foreach($temp_options as $unit) {
$opt = optionize($unit);
echo "<option value=\"{$opt}\"";
if($from_unit == $opt) { echo " selezionato"; }
echo ">{$unit}</option>";
}
?>
</select>
</div>
<div class="entry">
<label>A:</label>&nbsp;
<input type="text" name="to_value" value="<?php echo float_to_string($to_value); ?>" />&nbsp;
<select name="to_unit">
<?php
foreach($temp_options as $unit) {
$opt = optionize($unit);
echo "<option value=\"{$opt}\"";
if($to_unit == $opt) { echo " selezionato"; }
echo ">{$unit}</option>";
}
?>
</select>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
<br />
<a href="index.php">Torna al menù</a>
</div>
</body>
</html>

La pagina velocita.php

Siamo quasi giunti al termine di questo nostro progetto ed è necessario creare la pagina velocita.php con il codice che segue:

<?php
require_once('includes/functions.php');
$from_value = '';
$from_unit = '';
$to_unit = '';
$to_value = '';
if(isset($_POST['submit'])) {
$from_value = $_POST['from_value'];
$from_unit = $_POST['from_unit'];
$to_unit = $_POST['to_unit'];
$to_value = convert_speed($from_value, $from_unit, $to_unit);
}
$speed_options = array(
"feet per second",
"miles per hour",
"meters per second",
"kilometers per hour",
"knots"
);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Convertitore di Velocità</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main-content">
<h1>Convertitore di Velocità</h1>
<form action="" method="post">
<div class="entry">
<label>Da:</label>&nbsp;
<input type="text" name="from_value" value="<?php echo $from_value; ?>" />&nbsp;
<select name="from_unit">
<?php
foreach($speed_options as $unit) {
$opt = optionize($unit);
echo "<option value=\"{$opt}\"";
if($from_unit == $opt) { echo " selezionato"; }
echo ">{$unit}</option>";
}
?>
</select>
</div>
<div class="entry">
<label>A:</label>&nbsp;
<input type="text" name="to_value" value="<?php echo float_to_string($to_value); ?>" />&nbsp;
<select name="to_unit">
<?php
foreach($speed_options as $unit) {
$opt = optionize($unit);
echo "<option value=\"{$opt}\"";
if($to_unit == $opt) { echo " selezionato"; }
echo ">{$unit}</option>";
}
?>
</select>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
<br />
<a href="index.php">Torna al menù</a>
</div>
</body>
</html>

Infine la pagina volume.php

Ecco l’ultima procedura che dovrete realizzare, la pagina volume.php:

<?php
require_once('includes/functions.php');
$from_value = '';
$from_unit = '';
$to_unit = '';
$to_value = '';
if(isset($_POST['submit'])) {
$from_value = $_POST['from_value'];
$from_unit = $_POST['from_unit'];
$to_unit = $_POST['to_unit'];
$to_value = convert_volume($from_value, $from_unit, $to_unit);
}
$volume_options = array(
'cubic inches',
'cubic feet',
'Imperial gallons',
'Imperial quarts',
'Imperial pints',
'Imperial cups',
'Imperial ounces',
'Imperial tablespoons',
'Imperial teaspoons',
'US gallons',
'US quarts',
'US pints',
'US cups',
'US ounces',
'US tablespoons',
'US teaspoons',
'cubic centimeters',
'cubic meters',
'liters',
'milliliters'
);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Convertitore di Volume</title>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="main-content">
<h1>Convertitore di Volume</h1>
<form action="" method="post">
<div class="entry">
<label>From:</label>&nbsp;
<input type="text" name="from_value" value="<?php echo $from_value; ?>" />&nbsp;
<select name="from_unit">
<?php
foreach($volume_options as $unit) {
$opt = optionize($unit);
echo "<option value=\"{$opt}\"";
if($from_unit == $opt) { echo " selected"; }
echo ">{$unit}</option>";
}
?>
</select>
</div>
<div class="entry">
<label>To:</label>&nbsp;
<input type="text" name="to_value" value="<?php echo float_to_string($to_value); ?>" />&nbsp;
<select name="to_unit">
<?php
foreach($volume_options as $unit) {
$opt = optionize($unit);
echo "<option value=\"{$opt}\"";
if($to_unit == $opt) { echo " selected"; }
echo ">{$unit}</option>";
}
?>
</select>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
<br />
<a href="index.php">Torna al menù</a>
</div>
</body>
</html>

La procedura completa per il progetto Convertirore unità di misura

Vi abbiamo proposto tutte le pagine in linguaggio PHP per realizzare questo progetto. Vorremmo soltanto ricordarvi l’insieme delle procedure e dei file che dovranno essere contenuti nella cartella di questo progetto da inserire nel vostro server web per le prove:

area.php
includes/function.php
index.php
lunghezza.php
massa.php
styles.css
temperatura.php
velocita.php
volume.php

Test del Convertitore unità di misura

Abbiamo scritto qualche riga di codice nel linguaggio PHP per gestire le conversioni tra le unità di misura. Adesso verifichiamone il funzionamento:

Conversione delle unità di misura

Considerazioni finali

Abbiamo visto in questo articolo uno script su come creare un convertitore di unità di misura con il linguaggio PHP. Ricordiamo che abbiamo dedicato una intera sezione di questo Portale al linguaggio di programmazione PHP. In questa sezione oltre a tanti esempi di codice, troverete anche strumenti utili per la programmazione come Framework, librerie e tanto altro. Vi invitiamo quindi a visitare questa sezione del sito e ricordiamo che è disponibile anche una sezione esempi di codice PHP come quello che abbiamo proposto in questo articolo.