Author Topic: forecast-summary.php & Trim command Help  (Read 415 times)

0 Members and 1 Guest are viewing this topic.

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2297
    • CNYWeather
forecast-summary.php & Trim command Help
« on: February 28, 2018, 07:42:11 AM »
There are a few of us running a script on our front page, Forecast Summary.
It takes the forecast discussion and trims it down into a nice neat text file for display.

It's the same as forecast-discussion.php except for the trim feature. It worked well up until yesterday
with the latest NWS changes. I have the file working except for the trim command. The enrite page displays
in the cache file.

What we used to get was:

Code: [Select]
.SYNOPSIS...
High pressure over the area will slide east and allow a complex
storm system to approach the area from the Ohio valley. This
storm will bring rain, and then snow to the area beginning late
Thursday and continuing into the weekend.

&&

and this would display on our pages. Would the trim command need to be modified with the
NWS changes yesterday?

Here's what the trim looks like withing the script
Code: [Select]
preg_match('|<pre[^>]*>(.*)</pre>|Usi',$html,$matches);
 $discussion = $matches[1]; // now have the forecast as a string with \n delimiters

$discussion  = trim($matches[1]); // prevent extra white space at beginning and end
$discussion = str_replace(array("\r", "\n"), ' ', $discussion); //delete the linefeeds in the middle
$sstring = 'SYNOPSIS'; // start of synopis quick text
$estring = '&&'; // first divider
$start = strpos($discussion,$sstring); // starting position of where to keep
$end = strpos($discussion,$estring); // end of where to keep
$discuss = substr($discussion, $start+0, ($end-1-$start)); // new text (too long to print in cell format)
$charwrap = round($pagewidth/7.25);
$discussion = wordwrap ($discuss); // for cell phone roughly 8:1 ratio characters.

Will we need to start from scratch once again?

Tony
« Last Edit: February 28, 2018, 08:04:42 AM by CNYWeather »
Tony




Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: forecast-summary.php & Trim command Help
« Reply #1 on: February 28, 2018, 10:27:20 AM »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline CNYWeather

  • Forecaster
  • *****
  • Posts: 2297
    • CNYWeather
Re: forecast-summary.php & Trim command Help
« Reply #2 on: February 28, 2018, 10:39:57 AM »
Hmm. I'll have to take a look tonight and see where I went wrong Ken. THANK YOU!!
Tony




 

anything