[Tfug] Regexps

Robert Hunter hunter at tfug.org
Wed May 2 19:47:15 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.

Php is not *my* strength, but if you managed to get 2984 into a variable,
then 29 is the quotient ( integer division ) of 2984/100, and 84 is the
remainder ( modulus ).


-- 
Rob




More information about the tfug mailing list