Jump to content

Get some texts from the content of a page


kleidi24

Recommended Posts

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 by kleidi24
Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.