Jump to content

dondmite

New Members
  • Posts

    2
  • Joined

  • Last visited

dondmite's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I know it was definitely tiredness that got the better of me. I took a couple of hours rest then came back to the problem. All of a sudden it was staring me right in the face. I forgot to escape the slash. My code should have been. if (preg_match('/^(M?[0-9]{2})\/(M?[0-9]{2}|[X]{2})?$/',$part,$pieces)) { I left out the back slash shown in red above. By the way, the code was not doing any matching thus causing all of the dependent functions to stop working.
  2. I am trying to convert some PHP code, changing all ereg to preg_match but ran into a problem where one of my statements is refusing to cooperate. The statement in question is shown on the first line in the code snippet below: . . if (ereg('^(M?[0-9]{2})/(M?[0-9]{2}|[X]{2})?$',$part,$pieces)) { $tempC = (integer) strtr($pieces[1], 'M', '-'); $tempF = round(1.8 * $tempC + 32); get_wind_chill($tempF, $wxInfo); // Other dependent functions . } The new change to the ereg line I am trying to use is: . if (preg_match('/^(M?[0-9]{2})/(M?[0-9]{2}|[X]{2})?$/',$part,$pieces)) { . The code looks for a string like 30/25 or 08/07 or M01/M11 or 07/M01 - temperatures and dewpoints respectively as reported in METARs - (Meteorological Reports), where M represents the "-" for negative values. The ereg version works perfectly fine and has been doing so for several years. Now that I'm updating the code, adding some new functions and removing deprecated features like ereg, the very last ereg line needing to be changed is mis-behaving. Maybe I am tired and not seeing what else needs to be changed. Could you please tell me what is wrong here why my preg_match version in this remaining line is refusing to work. Thanks in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.