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