Page 1 of 1

Help retrieving currency from a site

Posted: Mon Aug 21, 2006 10:50 pm
by Think Pink
hello, pls advice how could I retrieve currency values from a site.

this is the table structure where currencyes are stored, but have no ideea how should I retrieve them.
Currencies are changing each day.

$site_name_example = "www.example.com/currency.php";

Code: Select all

<table CELLSPACING="0" CELLPADDING="5" width="100%">
    <tr>
      <td WIDTH="30%" bgcolor="#808080"  HEIGHT="16" align="left"  class="tableHead">Currency</td>
      <td WIDTH="25%" bgcolor="#808080"  HEIGHT="16" align="center"  class="tableHead">Symbol</td>
      <td WIDTH="21%" bgcolor="#808080"  HEIGHT="16" align="right"  class="tableHead">Buy</td>
      <td WIDTH="21%" bgcolor="#808080"  HEIGHT="16" align="right"  class="tableHead">Sell</td>
    </tr>  
    <tr class="normal">
	   <td class="normal" bgcolor="#FFFFFF" align="left">1 AMERICAN DOlLAR</td>
	   <td class="normal" bgcolor="#FFFFFF" align="center">USD</td>
	   <td class="normal" bgcolor="#FFFFFF" align="right">2.7018</td>
	   <td class="normal" bgcolor="#FFFFFF" align="right">2.7919</td>
	   </tr>
    <tr class="normal">
	   <td class="normal" bgcolor="#F3F3F3" align="left">1 EURO</td>
	   <td class="normal" bgcolor="#F3F3F3" align="center">EUR</td>
	   <td class="normal" bgcolor="#F3F3F3" align="right">3.4900</td>
	   <td class="normal" bgcolor="#F3F3F3" align="right">3.5600</td>
	   </tr>
	<tr class="normal">
	   <td class="normal" bgcolor="#FFFFFF" align="left">1 LIRA STERLINA</td>
	   <td class="normal" bgcolor="#FFFFFF" align="center">GBP</td>
	   <td class="normal" bgcolor="#FFFFFF" align="right">5.0687</td>
	   <td class="normal" bgcolor="#FFFFFF" align="right">5.2638</td>
	</tr>
</table>
thx in advance

Posted: Mon Aug 21, 2006 10:53 pm
by feyd
strip_tags() or the Useful Post on a slightly smarter one may be of interest. After that, maybe and explode()?

Posted: Mon Aug 21, 2006 11:13 pm
by Think Pink
ok, thx, that's a good ideea, and it seems to be working, but how could I locate a specific line?

Posted: Mon Aug 21, 2006 11:15 pm
by feyd
That would depend on the line. strpos() may work, preg_match() may work too. Which one to use depends on what you're looking for.

Posted: Tue Aug 22, 2006 1:28 am
by Think Pink
i'm back. sorry
i have something but not good.


my code

Code: Select all

$file = fopen("http://localhost/test3.php", "r");

while (!feof($file)) 
{ 
   $line = fgets($file, 1024); 
   if (eregi('<td class="normal" bgcolor="#FFFFFF" align="right">(.*)</td>', $line, $out))     {
   echo $out[1] . "<br />";
   }
   if (eregi('<td class="normal" bgcolor="#F3F3F3" align="right">(.*)</td>', $line, $out))     {
   echo $out[1] . "<br />";
   }
}
fclose($file);
this outputs like this
2.7018
2.7919
3.4900
3.5600
5.0687
5.2638
2.1899
2.2742
0.4636
0.4814
0.3756
0.3901
0.0232
0.0241
2.3934
2.4855
0.4287
0.4452
2.0435
2.1222
0.0124
0.0129

2 problems here
1. to manny results (i'm interested only in the first 4 results)
2. those 4 results should output like this
USD 2.7018 2.7919
EUR 3.4900 3.5600

anny advices?

Posted: Tue Aug 22, 2006 1:32 am
by feyd
  1. preg_match()
  2. count to four, kill the loop
  3. vary your output based on what the current count is.