Jump to content


Photo

Convertetemperatura()


  • Faça o login para participar
Nenhuma resposta neste tópico

#1 Timberwolves

Timberwolves

    Novato no fórum

  • Usuários
  • 16 posts
  • Sexo:Não informado

Posted 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>";





1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq