regular expression help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

regular expression help

Post by devork »

Code: Select all

ZAR South Africa Rand                     0.1640715975          6.0949001247
what regular expression to extract the 3 values from string?

feeling sleepy and can't concentrate :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

since you only posted a single example of data...

Code: Select all

$array = preg_split('#\s{2,}#', $text, -1, PREG_SPLIT_NO_EMPTY);
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

Code: Select all

Rates as of 2005.01.09 23:52:38 UTC (GMT). Base currency is USD.

 Currency Unit USD per Unit Units per USD
 ================================ =================== ===================
 USD United States Dollars 1.0000000000 1.0000000000
 EUR Euro 1.3064862009 0.7654118347
 GBP United Kingdom Pounds 1.8707816106 0.5345359364
 CAD Canada Dollars 0.8119239017 1.2316425195
 AUD Australia Dollars 0.7580789363 1.3191238433
 JPY Japan Yen 0.0095513045 104.6977402264
 INR India Rupees 0.0227712622 43.9150009155
 NZD New Zealand Dollars 0.6949126365 1.4390298112
 CHF Switzerland Francs 0.8441286111 1.1846536023
 ZAR South Africa Rand 0.1640715975 6.0949001247
:wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

untested

Code: Select all

#^\s*(ї\D])*\s*(ї\d\.]+)\s*(ї\d\.]+)\s*$#m
designed for preg_match_all.
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

well above RE is not working

Code: Select all

USD United States Dollars                 1.0000000000          1.0000000000
EUR Euro                                  1.3393162434          0.7466496467
GBP United Kingdom Pounds                 1.9250040832      0.5194794176
CAD Canada Dollars                        0.8288076450        1.2065525771
AUD Australia Dollars                     0.7930480874   1.2609575836
JPY Japan Yen                             0.0096173584     103.9786560790
INR India Rupees                          0.0229621125        43.5500000000
I'm trying to extract currency rates from this text body.

I'm playing with it ,
thanx for your help !
Last edited by devork on Thu Mar 10, 2005 11:13 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

so play with it.. :roll:
Post Reply