Re: preg_match? Or something else?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 )

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux