[Tfug] Regexps
Christopher Robbins
robbinsc at gmail.com
Wed May 2 21:13:16 MST 2007
On 5/2/07, Robert Hunter <hunter at tfug.org> wrote:
>
> > 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 ).
I came in to second what Rob said...Beat me to the punch, I guess :)
Why use a regexp when math can save the day?
-Chris
--
Chris Robbins
Systems Programmer
Department of English - University of Arizona
http://www.homerengineeringcorp.net
More information about the tfug
mailing list