Re: preg_match? Or something else?

From: Date: Fri, 02 Apr 2010 23:48:38 +0000
Subject: Re: preg_match? Or something else?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-303760@lists.php.net to get a copy of this message
Jim Lucas wrote: > Ashley M. Kirchner wrote: >> I have an array that's created as follows: >> >> >> >> $string = "73G 146C 311- 309.1C"; >> >> >> Anyone want to take a stab at it? >> >> > > Conditionals are your friend! > > <plaintext><?php > > $string = "73G 146C 311- 309.1C"; > > $arr = preg_split("/[\s]+/", $string); > > print_r($arr); > > foreach ( $arr AS $item ) { > > preg_match('|^(?P<location>\d+)\.?(?P<decimal>\d*)(?P<letter>[A-Z-])|', > $item, > $matches); > > print_r($matches); > } > > ?> > or w/ preg_match_all: <?php $regex = '/(([0-9]+)([^0-9])((?:[0-9]|\s+)))/'; $string = "73G 146C 311- 309.1C"; preg_match_all( $regex , $string , $matches ); print_r( $matches )

« previous php.general (#303760) next »