kleidi24 Posted December 2, 2013 Share Posted December 2, 2013 (edited) Hello, I was looking around for a solution to get some texts from a webpage. I was searching around for some solutions but i can't make it works. I have a national bank webpage that every day shows the official exchange rates. I want to get thos official rates once a day and cache it. The bank page shows this html code: [...] <tr> <td width="13" height="15" align=right> <img src="bullet_light_grey.gif"> </td> <td width="3"> <img src="spacer.gif" width="3" height="18"> </td> <td class="arial11Light">USD / ABC</td> <td class="arial11Light" align=right> 103.51 </td> </tr> <tr> <td width="13" height="15" align=right> <img src="bullet_light_grey.gif"> </td> <td width="3"> <img src="spacer.gif" width="3" height="18"> </td> <td class="arial11Light">EUR / ABC</td> <td class="arial11Light" align=right> 140.26 </td> </tr> <tr> <td width="13" height="15" align=right> <img src="bullet_light_grey.gif"> </td> <td width="3"> <img src="spacer.gif" width="3" height="18"> </td> <td class="arial11Light">GBP / ABC</td> <td class="arial11Light" align=right> 169.65 </td> </tr> [...] This is the code where is found my needed informations. Now, what i need is the currency and the value. Ex: USD / ABC - 103.51 Can you help me to find a way to extract this informations? Thank you! Edited December 2, 2013 by kleidi24 Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted December 2, 2013 Share Posted December 2, 2013 if they're always in the same order, you could use preg_match_all() to grab the values in order. Assuming you've already grabbed the content and put it in a variable named $content. preg_match_all('/([0-9]{2,3}\.[0-9]{2})/',$content,$matches); print_r($matches); would return: Array ( [0] => Array ( [0] => 103.51 [1] => 140.26 [2] => 169.65 [3] => 113.88 ) [1] => Array ( [0] => 103.51 [1] => 140.26 [2] => 169.65 [3] => 113.88 ) ) Quote Link to comment Share on other sites More sharing options...
kleidi24 Posted December 3, 2013 Author Share Posted December 3, 2013 Hello there. Thank you for your reply and for helping me. Those are always in the same order but the problem is that, are not the only numbers in the page and with way you thought, the return array may catch other numbers there. Or i'm wrong? Thanks! Quote Link to comment Share on other sites More sharing options...
dalecosp Posted December 3, 2013 Share Posted December 3, 2013 The canonical way to do this is with DOMDocument; however, you should probably check with the bank (or at least search the bank's site) to see if this is even permitted by the bank's Terms of Service. You may have to call or write to them and ask if an API exists. Alternately, there are quite a few sites that can offer this sort of service, I think. For example, Google probably has an API (they certainly have the app online themselves). Quote Link to comment Share on other sites More sharing options...
kleidi24 Posted December 3, 2013 Author Share Posted December 3, 2013 Thank you for your reply and explanation. The bank don't have an api yet. I'll go with google, yahoo or some other provider to be sure that everything will work as it should. Thanks again! 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.