Author Topic: Best Way to Fix a Split  (Read 294 times)

0 Members and 1 Guest are viewing this topic.

Offline DaculaWeather

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 3206
    • North Georgia Weather
Best Way to Fix a Split
« on: March 27, 2019, 10:04:41 AM »
How can I fix this?  My hosting server is running Php7 and splits are a no-no.

// strip trailing units from a measurement
function strip_unit ($data) {
  preg_match('/([\d\.\+\-]+)/',$data,$t);
  return $t[1];
}

// THIS PORTION IS COURTESY OF RAINER AT http://www.bashewa.com
// now split temps and dates for warmest/coldest night/day records
   list($mwarmestdayonrecord_temp, $date) = split("[ ]+on:[ ]+", $mwarmestdayonrecord);
   $date = strtotime($date);
   $mwarmestdayonrecord_date = date($SITE['dateOnlyFormat'],$date);

   list($mwarmestnightonrecord_temp, $date) = split("[ ]+on:[ ]+", $mwarmestnightonrecord);
   $date = strtotime($date);
   $mwarmestnightonrecord_date = date($SITE['dateOnlyFormat'],$date);

   list($mcoldestdayonrecord_temp, $date) = split("[ ]+on:[ ]+", $mcoldestdayonrecord);
   $date = strtotime($date);
   $mcoldestdayonrecord_date = date($SITE['dateOnlyFormat'],$date);

   list($mcoldestnightonrecord_temp, $date) = split("[ ]+on:[ ]+", $mcoldestnightonrecord);
   $date = strtotime($date);
   $mcoldestnightonrecord_date = date($SITE['dateOnlyFormat'],$date);

// end of functions
//=========================================================================

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9297
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Best Way to Fix a Split
« Reply #1 on: March 27, 2019, 10:35:57 AM »
Ahh... the split() function was removed in PHP7.

You can change all the
Code: [Select]
split("[ ]+on:[ ]+", to
Code: [Select]
preg_split("|\s+on:\s+|", and I think that will fix it up.
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 DaculaWeather

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 3206
    • North Georgia Weather
Re: Best Way to Fix a Split
« Reply #2 on: March 27, 2019, 10:40:23 AM »
Woohoo!! Easy enough! Thanks Ken!!!!  [tup]