Hi there,
I am stuck on something that I want to try and achieve and that is to change 2 words using PHP from a public source which is Weather Underground.
Here is most of the script which controls the weather underground weather forecast on Newton Poppleford Weather:
[code]// fixup temperature
$doESfixup = false;
preg_match_all(’!.\s+([^:]+):{0,1}\s+([\d|-]+)(°|°|°|C|F)!Uis’,$WUforecasttext[$n],$temp);
if(isset($temp[1][0]) and strpos($temp[1][0],'.') !== false) {
if( $doDebug) { $Status .= "<!-- prune temperature text from '".$temp[1][0]."'"; }
$t = trim(substr($temp[1][0],strpos($temp[1][0],'.')+1));
$temp[1][0] = $t;
if( $doDebug) { $Status .= " to '$t' -->\n"; }
}
if(!isset($temp[2][0])) {
if( $doDebug) { $Status .= "<!-- failed first temperature match; trying again. -->\n"; }
preg_match_all('!\.\s+([^:]+)\:\s+([\d|-]+)°!s',$WUforecasttext[$n],$temp);
}
if(!isset($temp[2][0])) {
// . Maks.: 21° C.
if( $doDebug) { $Status .= "<!-- failed second temperature match; trying again. -->\n"; }
preg_match_all('!\.\s+(\S+)\s+\S+\s+([\d|-]+)°!s',$WUforecasttext[$n],$temp);
}
if(!isset($temp[2][0])) {
// . Maks.: 21° C.
if( $doDebug) { $Status .= "<!-- failed third temperature match; trying again. -->\n"; }
// this is a hack for the lang=es version which looks like
// Alta de nn
// for all of them High and Low. Hopefully they'll add a degree sign and fix night 'Alta' to 'Min'
preg_match_all('!\.\s+(Alta)\s+de\s+([\d|-]+)!s',$WUforecasttext[$n],$temp);
$doESfixup = true;
}
if($doRTL) { // try the Hebrew
if( $doDebug) { $Status .= "<!-- trying lang='he' temperature match. -->\n"; }
preg_match_all('! (\S+)\s{0,1}\xD7\x99\xD7\x9E\xD7\x95\xD7\x9D ([\d|-]+)!',$WUforecasttext[$n],$temp); // min/max for Hebrew
}
if ( $doDebug) {
$Status .= "<!-- temp[$n]='" . print_r($temp,true) . "' -->\n";
}
$color = '#FF0000';
$tday = trim($WUforecastday[$n]);
$yday = $tday;
if($n > 0) {$yday = trim(strip_tags($WUforecastday[$n-1])); }
$tdayblanks = count(explode(" ",$tday)) -1; // counts the number of blanks in todays name
if($doDebug) {
$Status .= "<!-- DayNight tday'$tday' yday='$yday' tdayblanks=$tdayblanks -->\n";
}
if ( ($tdayblanks > 0) or
(strlen($tday) > strlen($yday) and stripos($tday,$yday) !== false)
) {
// the above IF checks to see if the todays name is longer than yesterdays name, and
// that yesterdays day name is present in todays name .. this probably means it's a
// night time forecast, so treat it as a 'low' temp, and change the icon to night-time
// if needed.
if($doDebug) {
$Status .= "<!-- night time icon selected -->\n";
}
if(substr($WUforecasticon[$n],0,3) <> 'nt_') {
$WUforecasticon[$n] = 'nt_'.$WUforecasticon[$n]; // funny.. they stopped using day/night icons
}
$color = '#0000FF';
}
// special handling for bad (currently) Spanish translation on WU
if($doESfixup && isset($temp[1][0]) and $temp[1][0] == 'Alta') {
$temp[1][0] = (substr($color,0,3) == "#FF")?'Máx':'Min';
}
// end special Spanish handling
$WUforecasttemp[$n] = "<span style=\"color: $color;\">";
$beforeError = error_reporting();
error_reporting($beforeError & ! E_NOTICE);
if($doIconv) {$thilo = iconv($charsetInput,$charsetOutput.'//TRANSLIT',$temp[1][0]); }
else { $thilo = $temp[1][0]; }
error_reporting($beforeError);
if ($doDebug) {
$Status .= "<!-- $charsetInput temp[1][0]='" . $temp[1][0] . "' $charsetOutput thilo='$thilo' -->\n";
}
if(isset($temp[1][0]) and strlen($thilo) < 2) {$thilo = trim($temp[1][0]); } // in case the iconv fails
if(isset($temp[2][0])) {$WUforecasttemp[$n] .= $thilo . ' '. preg_replace('|°|','°',$temp[2][0]);}
$WUforecasttemp[$n] .= '°C</span>'; // assemble the temperature
if ($doDebug) {
$Status .= "<!-- forecasttemp[$n]='" . $WUforecasttemp[$n] . "' -->\n";
}
$temp = explode('.',$WUforecasttext[$n]); // split as sentences (sort of).
$WUforecastcond[$n] = trim($temp[0]); // take first one as summary.
if ($doDebug) {
$Status .= "<!-- forecastcond[$n]='" . $WUforecastcond[$n] . "' -->\n";
}
if (count(explode(' ',$WUforecastcond[$n])) > $maxForecastLegendWords) {
if(function_exists('langtransstr')) {
$WUforecastcond[$n] = langtransstr($NWSiconlist[$WUforecasticon[$n]][1]); // use our description instead
} else {
$WUforecastcond[$n] = $NWSiconlist[$WUforecasticon[$n]][1]; // use our description instead
}
$Status .= "<!-- replaced forecastcond[$n]='" . $WUforecastcond[$n] . "' -->\n";
}
if(preg_match('||',$WUforecastday[$n]) ) {
$WUforecastday[$n] = preg_replace('|<br/>|','<br/>',$WUforecastday[$n],1);
} else {
$WUforecastday[$n] .= "<br/>";
}
$WUforecasticons[$n] = $WUforecastday[$n] . "<br/>" .
img_replace($WUforecasticon[$n],$WUforecastcond[$n],$WUforecastpop[$n]) . "<br/>" .
$WUforecastcond[$n];
if ($doDebug) {
$Status .= "\n";
}
$n++;
}
[/code]
Simply, all I want to do is change the word “High” to “High:” and “Low” to “Low:”. But, I cannot find anything to do with the word anywhere in the script. You can see the “High” word and “Low” word, here: http://newton-poppleford-weather.co.uk/
Sorry that there is a lot of script and I appreciate any advice or help given.
Thanks,
William