Question : Help with preg_match in PHP

Hi - I'm trying to split up a metar using preg_match.  For example here is a metar
$metar = "2010/08/01 22:00 CYYZ 012200Z 14005KT 15SM SCT031TCU BKN069 OVC300 23/18 A2981 RETS RMK TCU4AC3CI1 SLP097";

For instance I want to preg_match SM however I need to pull the previous 2 numbers.  How do I use the offset correctly to get it?  If I want to pull BKN069 matching BKN and pull the next 3 numbers.

Thanks!

Answer : Help with preg_match in PHP

Or with a capturing group directly
This matches anything after BKN up to the next space.
1:
2:
3:
4:
5:
6:
7:
8:
9:
<?php
$metar = "2010/08/01 22:00 CYYZ 012200Z 14005KT 15SM SCT031TCU BKN069 OVC300 BKN069 BKN079 23/18 A2981 RETS RMK TCU4AC3CI1 SLP097";
preg_match("/BKN([^ ]*)/", $metar, $matches);
if ($matches) {
	echo $matches[1];
} else {
	echo "no match";
}
?>
Random Solutions  
 
programming4us programming4us