hackerkts Posted April 24, 2007 Share Posted April 24, 2007 I'm using the script posted by HuggieBear at http://www.phpfreaks.com/forums/index.php/topic,124091.msg513961.html#msg513961 I'm trying to modify it and make it works for all the currencies show on that page, currently I having problem to get the exchange rates for United States Dollar and Euro working but I couldn't. <?php $url = "http://newsvote.bbc.co.uk/1/shared/fds/hi/business/market_data/currency/11/12/default.stm"; $raw_data = file_get_contents($url); preg_match('/United States Dollar.*?right">([^<]+)/is', $raw_data, $USD); preg_match('/Euro.*?right">([^<]+)/is', $raw_data, $EUR); $ex_rate_USD = number_format($USD[1], 2, '.', ''); $ex_rate_EUR = number_format($EUR[1], 2, '.', ''); ?> I think it's because the pattern for USD and EUR is different from the rest, by the way. Can someone explain to me the pattern used here? /United States Dollar.*?right">([^<]+)/is Thanks in advance. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 What are you trying to do ? /United States Dollar.*?right">([^<]+)/is i am not going to explain that regex.. its used for United States Dollar Hello Word or <blar United States Dollar Hello Word right"> Quote Link to comment Share on other sites More sharing options...
hackerkts Posted April 24, 2007 Author Share Posted April 24, 2007 Thanks for the reply, I'm trying to get the value under "£1 buys" for United States Dollar and Euro. The one in the red box, Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 i think your need to learn RegEx Quote Link to comment Share on other sites More sharing options...
hackerkts Posted April 24, 2007 Author Share Posted April 24, 2007 i think your need to learn RegEx That's one of the hardest part in PHP for me to learn it, nevermind i willing to try. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 its fun after awhile but its not something i like to explain! Quote Link to comment Share on other sites More sharing options...
effigy Posted April 24, 2007 Share Posted April 24, 2007 <pre> <?php $url = "http://newsvote.bbc.co.uk/1/shared/fds/hi/business/market_data/currency/11/12/default.stm"; $raw_data = file_get_contents($url); preg_match_all('#(?<=class="statsclick">)(.+?)</A></td>\s+<td[^>]+>(.+?)</td>#', $raw_data, $matches, PREG_SET_ORDER); // Create associative array. $rates = array(); foreach ($matches as $match) { $rates[$match[1]] = $match[2]; } unset($matches); print_r($rates); ?> </pre> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 Oww love the way you did that, very impressive effigy (well to me) still learning RegEx, i have not covered PREG_SET's yet Quote Link to comment Share on other sites More sharing options...
hackerkts Posted April 24, 2007 Author Share Posted April 24, 2007 I'm gona start learning regex if it's fun =D Thanks effigy! It's short and sweet. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.