[Tfug] Regexps

Josh Miller joshnmiller at comcast.net
Thu May 3 08:19:10 MST 2007


sounds like you want PHP's explode function - it will split a string 
into an array of strings based on another string

so, $result=explode(".","29.42");  gives you

$result[0]="29"
$result[1]="42"

-Josh



George Cohn 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.
> 
> Note: Programming is *not* my strong strength.  ;-)
> 
> George Cohn
> 
> _______________________________________________
> Tucson Free Unix Group - tfug at tfug.org
> Subscription Options:
> http://www.tfug.org/mailman/listinfo/tfug_tfug.org
> 




More information about the tfug mailing list