[Tfug] Regexps

George Cohn gwcohn at simplybits.net
Wed May 2 19:34:43 MST 2007


I'm trying to figure out a pair of regexps that will take a number like 
29.84 and give me back the first two digits which I can assign to a 
variable, then it will give me the last two digits that I can assign to 
a second variable.

What I am trying to do is parse an xml page from the weather station to 
pull out the barometric pressure.  This is what I have so far in php:

#get barometric pressure

if
(preg_match("/<pressure_in>([0-9.]+)<\/pressure_in>/i",$weatherPage,$matches))
{
$currentPressure=$matches[1];
}

This is the string I'm trying to parse:

<pressure_in>29.84</pressure_in>

Unfortunately, this gives me a number like 2984 when what I want is two 
separate numbers, 29 and 84.

Note: Programming is *not* my strong strength.  ;-)

George Cohn



More information about the tfug mailing list