$msg
\n"; return; } $pt = file($plaintextFile); // fix missing space at start of line if need be foreach ($pt as $i => $line) { if(substr($line,0,1) != ' ') {$pt[$i] = ' ' . $line;} } $plaintext = implode('',$pt); // get the plaintext file. // preprocess.. mark divisions in the forecast days for later parsing $plaintext = preg_replace('![\n][\r|\n]+!s',"\n \n",$plaintext); $plaintext = preg_replace('![\r|\n]+ [\r|\n]+!s',"\t\t",$plaintext); $plaintext .= "\t\t"; // make sure a delimiter is at the end too. $plaintext = preg_replace('|_|is','',$plaintext); // remove dashed line in front // Find city and update date if (preg_match('|WXSIM text forecast for (.*), initialized at\s+(.*)|i',$plaintext,$matches)) { $WXSIMcity = PPget_lang(trim($matches[1])); $wdate = trim($matches[2]); $Status .= "\n"; // there are LOTS of formats of the date stamp in plaintext.txt // 012345678901234567890 // 20:00 Feb 21, 2007 // 15:00 02 Apr, 2007 // 8:00 PM Mar 24, 2007 // 12:00 AM 24 Mar, 2007 // 17:00Z 05 Nov, 2007 $wdateParts = preg_split("/[\s,]+/", $wdate); // $Status .= "\n"; $i=0; if (preg_match('!AM|PM!i',$wdateParts[1]) ) { // got US style date. list($wHrs,$wMins) = explode(':',$wdateParts[0]); if (strtolower($wdateParts[1]) == 'pm' and $wHrs <> 12 ) {$wHrs += 12; } if (strtolower($wdateParts[1]) == 'am' and $wHrs == 12 ) {$wHrs = '00'; } $wTime = "$wHrs:$wMins"; $i=1; } else { $wTime = $wdateParts[0]; } if (preg_match('!\d+!',$wdateParts[$i+1]) ) { // got day in 1, month in 2 (+offset) $wDay = $wdateParts[$i+1]; $wMon = $wdateParts[$i+2]; } else { $wDay = $wdateParts[$i+2]; $wMon = $wdateParts[$i+1]; } $wYear = $wdateParts[$i+3]; // $wdate = preg_replace('|(\S+)\s+(\S+)\s+(\S+),\s+(\S+)|s',"$2-$3-$4 $1:00 ".date('O',time()),$wdate); if(preg_match('|Z|i',$wTime) ) { // Zulu(GMT) time format $wTime = preg_replace('|Z|i','',$wTime); $wdate = "$wDay-$wMon-$wYear $wTime UTC"; $Status .= "\n"; $d = strtotime($wdate); $WXSIMupdated = PPget_lang(date('l',$d)) . ', ' . gmdate($timeFormat,$d) . ' UTC'; } else { $wdate = "$wDay-$wMon-$wYear $wTime " . date('O',time()); $Status .= "\n"; $d = strtotime($wdate); $WXSIMupdated = PPget_lang(date('l',$d)) . ', ' . date($timeFormat,$d); } } // split up the forecast days and texts // good preg_match_all('![\r|\n]+\s+(.*):\s(.*)[\r|\n]+ [\r|\n]+!Us',$plaintext,$matches); preg_match_all('!\t\s(.*):\s(.*)\t!Us',$plaintext,$matches); // split up the forecast // Main loop over each forecast text paragraph. for ($i=0;$i" . print_r($mtemp,true) . "\n"; $WXSIMpop[$i] = $mtemp[1]; $WXSIMpop[$i] = preg_replace('|less than |i','<',$WXSIMpop[$i]); if ($WXSIMpop[$i] == '<20') {$WXSIMpop[$i] = '10';} if ($WXSIMpop[$i] == 'near 100') { $WXSIMpop[$i] = '100'; } } // extract frost if (preg_match('!with\s+(.*)\s+frost.!is',$WXSIMtext[$i],$mtemp)) { // print "
" . print_r($mtemp,true) . "\n"; $WXSIMfrost[$i] = ucfirst($mtemp[1]) . ' frost'; if ($doTranslate) { // perform optional translation if $Language has entries reset ($Language); // process in order of the file $text = $WXSIMfrost[$i]; foreach ($Language as $key => $replacement) { $text = str_replace($key,$replacement,$text); } $WXSIMfrost[$i] = $text; } } // now look for harshest conditions first.. (in order in -data file if ($doDebug) { $Status .= "\n"; } reset($Conditions); // Do search in load order foreach ($Conditions as $cond => $condrec) { // look for matching condition if ($doDebug) { $Status .= "\n"; } if(preg_match("!$cond!i",$WXSIMtext[$i],$mtemp)) { list($dayicon,$nighticon,$condition) = explode("\t",$condrec); if (preg_match('!chance!i',$condition) and $WXSIMpop[$i] < $minPoP) { if ($doDebug) { $Status .= "\n"; } continue; // skip this one } if (preg_match("|$cond level|i",$WXSIMtext[$i]) and !preg_match("/(chance of $cond|$cond likely|$cond very likely)/i",$WXSIMtext[$i]) ) { if ($doDebug) { $Status .= "\n"; } continue; // skip 'snow level' and 'freezing level' entries } if ($doDebug) { $Status .= "\n"; } $WXSIMcond[$i] = PPget_lang($condition); if (preg_match('|night|i',$WXSIMday[$i])) { $WXSIMicon[$i] = $nighticon; } else { $WXSIMicon[$i] = $dayicon; } break; } } // end of conditions search // look for precipitation amounts reset($Precip); // Do search in load order foreach ($Precip as $pamt => $prec) { // look for matching precipitation amounts if(preg_match("!$pamt!is",$WXSIMtext[$i],$mtemp)) { list($amount,$units) = explode("\t",$prec); $WXSIMprecip[$i] = $amount . ' ' . $units; break; } } // end of precipitation amount search // look for Snow Accumulation reset($Snow); // Do search in load order foreach ($Snow as $pamt => $prec) { // look for matching precipitation amounts if(preg_match("!$pamt!is",$WXSIMtext[$i],$mtemp)) { list($amount,$units) = explode("\t",$prec); $WXSIMprecip[$i] .= "
testicon='$testicon'\n"; if (file_exists($iconDir . $testicon)) { $WXSIMicon[$i] = $testicon; } else { $WXSIMicon[$i] = $curicon; } } else { $WXSIMicon[$i] = $curicon; } if ($WXSIMtempdirect[$i] <> '') { $tempdirect = 'up.gif'; if (substr($WXSIMtempdirect[$i],0,1) == 'f') { $tempdirect='down.gif'; } $WXSIMtemp[$i] .= "
";
print "Testing links for ";
$thisLink = isset($_REQUEST['test'])?'&test='.$_REQUEST['test']:'';
print "lang=$lang ";
print "lang=en
\n";
print $linksList;
print "\n
| >
|
||||||
| > ";} echo $WXSIMupdated; if($doRTL) { echo "";} ?> | ||||||
| > ";} echo $updtime; if($doRTL) { echo "";} ?> | ||||||
|
| $WXSIMday[$i] | \n";
print "$WXSIMtext[$i] | \n"; print "\n"; } ?>
WXSIM forecast using WXSIM .
'.jpg') { } ?>