Actually, the reformat_forecast_temp() function has a lot of comments (showing the values from various forecast programs), but does have the 'meat' code of <?php
function reformat_forecast_temp($intemp) {
// change
// NWS: 'Hi <span style="color: #FF0000;">66 °F ↓</span>' to
// to 'Hi <span style="color: #FF0000;"><span class="convTemp>66 °F</span> ↓</span>'
// WXSIM '<span style="color: blue">Low: 43°</span>'
// to '<span style="color: blue">Low: <span class="convTemp">43°F</span></span>'
// WCFcst '<span style="color: #ff0000;">66°F</span>'
// to '<span style="color: #ff0000;"><span class="convTemp">66°F</span></span>'
// AWfcst '<span style="color: #ff0000;">18.9°C</span>'
// to '<span style="color: #ff0000;"><span class="convTemp">18.9°C</span></span>'
// DSfcst '<span style="color: #ff0000;">18°C</span><br/><span style="color: #0000ff;">6°C</span>'
// to '<span style="color: #ff0000;"><span class="convTemp">18°C</span></span><br/><span style="color: #0000ff;"><span class="convTemp">6°C</span></span>'
global $uomTemp;
$t = str_replace('°<',$uomTemp.'<',$intemp); // handle WXSIM w/no uom
$t = preg_replace_callback('!([\d]+)\s*°(F|C)!Us',
function ($M) {
return '<span class="convTemp">'.$M[1].'°'.$M[2].'</span>';
},
$t);
print "<!-- reformat_forecast\n in='$intemp'\nout='$t' -->\n";
return $t;
}
?>
the preg_replace_callback() function does the 'heavy lifting' by surrounding the actual temperature values (with units) in a
<span class="convTemp"></span> which ajaxWDwx3.js then handles the temperature conversion as needed. Only WXSIM temperatures (that have no units) needed a bit of special handling to put the $uomTemp unit in the HTML first, before the preg_replace_callback() does the <span> insertion. Fairly cool.. just two lines of operative code to handle getting it ready for the AJAX script to process as needed.
Then, for every <?php echo $forecasttemp[N]; ?>
now becomes <?php echo reformat_forecast_temp($forecasttemp[N]); ?>
to make the HTML.