kleidi24 Posted December 2, 2013 Share Posted December 2, 2013 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! Link to comment https://forums.phpfreaks.com/topic/284458-get-some-texts-from-the-content-of-a-page/ 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 ) ) Link to comment https://forums.phpfreaks.com/topic/284458-get-some-texts-from-the-content-of-a-page/#findComment-1461004 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! Link to comment https://forums.phpfreaks.com/topic/284458-get-some-texts-from-the-content-of-a-page/#findComment-1461030 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). Link to comment https://forums.phpfreaks.com/topic/284458-get-some-texts-from-the-content-of-a-page/#findComment-1461036 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! Link to comment https://forums.phpfreaks.com/topic/284458-get-some-texts-from-the-content-of-a-page/#findComment-1461135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.