PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Think Pink
Forum Contributor
Posts: 106 Joined: Mon Aug 02, 2004 3:29 pm
Post
by Think Pink » Mon Aug 21, 2006 10:50 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 21, 2006 10:53 pm
strip_tags() or the Useful Post on a slightly smarter one may be of interest. After that, maybe and
explode() ?
Think Pink
Forum Contributor
Posts: 106 Joined: Mon Aug 02, 2004 3:29 pm
Post
by Think Pink » Mon Aug 21, 2006 11:13 pm
ok, thx, that's a good ideea, and it seems to be working, but how could I locate a specific line?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 21, 2006 11:15 pm
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.
Think Pink
Forum Contributor
Posts: 106 Joined: Mon Aug 02, 2004 3:29 pm
Post
by Think Pink » Tue Aug 22, 2006 1:28 am
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Aug 22, 2006 1:32 am
preg_match()
count to four, kill the loop
vary your output based on what the current count is.