Jump to content


Timberwolves

Member Since 08/09/2005
Offline Last Active 06/10/2005, 15:42
-----

Topics I've Started

Convertetemperatura()

08/09/2005, 16:34

Não sei se vai ser útil para alguém, mas tá aí. Bem simples.

Sintaxe: converteTemperatura(TEMPERATURA)
Retorno: Array
Descrição: Identifica temperatura e converte em kelvin, celcius e fahrenheit
Bibliotecas: Nenhuma
Limitações: Nenhuma

function converteTemperatura ($vrTemp) {
    $parte = explode(" ",$vrTemp);
    $vr = trim($parte[0]);
    $undm = trim($parte[1]);
    
    switch ($undm) {
        case "C":
            $temp['celcius'] = number_format($vr,1,',','');
            $temp['kelvin'] = number_format($vr+273,1,',','');
            $temp['fahrenheit'] = number_format(($vr*1.8)+32,1,',','');
            break;
        case "F":
            $temp['celcius'] = number_format(($vr-32)/1.8, 1,',','');
            $temp['kelvin'] = number_format(($temp['celcius']+273),1,',','');
            $temp['fahrenheit'] = number_format($vr,1,',','');
            break;
        case "K":
            $temp['celcius'] = number_format($vr-273,1,',','');
            $temp['kelvin'] = number_format($vr,1,',','');
            $temp['fahrenheit'] = number_format(($temp['celcius']*1.8)+32,1,',','');
            break;
    }
 return $temp;
}

Exemplo de utilização:
convertendo 12 °C

$temp = converteTemperatura("12 C");
echo $temp['kelvin']." Kelvin </br>";
echo $temp['celcius']." °C </br>";
echo $temp['fahrenheit']." °F </br>";

IPB Skin By Virteq