Coding expertise needed to look over something for me please

Hi Folks

I am struggling to narrow down a wee bug with the risk assessment script for WXSim.

Sometimes, this script will get cut short when producing wind gust risks as seen below
for Saturday, Saturday night and Sunday, as you can see though, Friday and Sunday night
are fine???

Friday gusty winds are forecast. Expect winds southwest around 20 mph, gusting to 29 mph, in the morning, becoming 13 mph, gusting to 23 mph, in the afternoon.
Saturday gusty winds are forecast. Expect
Saturday Night gusty winds are forecast. Expect
Sunday gusty winds are forecast. Expect
Sunday Night gusty winds are forecast. Expect winds south-southwest around 19 mph, gusting to 27 mph.

Heres my plaintext for the above days

 Friday: Dense overcast in the morning, becoming mostly cloudy in the afternoon.

 A slight chance of rain. Windy and relatively mild. High 10. Wind southwest

 around 20 mph, gusting to 29 mph, in the morning, becoming 13 mph, gusting to 23

 mph, in the afternoon. Chance of precipitation 20 percent. Precipitation mostly

 less than 2 mm.

 

 Friday night: Partly to mostly cloudy in the evening, becoming mostly cloudy

 after midnight. Windy. Low 5, but temperatures rising after midnight. Wind

 southwest around 13 mph, gusting to 23 mph, in the evening, becoming 21 mph,

 gusting to 28 mph, after midnight.

 

 Saturday: Mostly cloudy. Windy and unusually mild. High 14. Wind southwest

 around 23 mph, gusting to 32 mph.

 

 Saturday night: Mostly cloudy to cloudy. Windy and relatively mild. Low 10. Wind

 southwest around 20 mph, gusting to 29 mph.

 

 Sunday: Cloudy in the morning, becoming mostly cloudy in the afternoon. Windy

 and unusually mild. High 12. Wind southwest around 18 mph, gusting to 28 mph.

 

 Sunday night: Cloudy. A slight chance of rain. Windy and relatively mild. Low 8.

 Wind south-southwest around 19 mph, gusting to 27 mph. Chance of precipitation

 20 percent. Precipitation mostly less than 2 mm.

and heres the code used

$gustpos = strpos($pdvb, 'gusting to');
if ($gustpos !== false) {
   $wndgust = substr($pdvb, $gustpos + 11, strpos($pdvb, ' ', $gustpos + 12) - $gustpos - 11);
   $wndsent = strpos($pdvb, ' Wind ');
   if ($wndgust >= $wgpreset) {
     if ($snpos !== false) {
       $bsstate .= "".$pdnm." gusty winds are forecast. Expect ";
       $bsstate .= str_replace('Wind', 'winds', substr($pdvb, $wndsent, strpos($pdvb, '. ', $wndsent) - $wndsent + 1));
       $bsstate .= " Blowing and drifting snow is possible, which may cause restrictions in visibility.";
       $bsstate .= '

';
     } else {
       $wgstate .= "".$pdnm." gusty winds are forecast. Expect ";
       $wgstate .= str_replace('Wind', 'winds', substr($pdvb, $wndsent, strpos($pdvb, '. ', $wndsent) - $wndsent + 1));
       $wgstate .= '

';

Could someone please take a look and see if you can see anything untoward
I was hoping it was something in the plaintext but nothing stands out?