I can't get value of parsed variable

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

Post Reply
mrtblt
Forum Newbie
Posts: 5
Joined: Mon Dec 10, 2007 7:40 am

I can't get value of parsed variable

Post by mrtblt »

I want to parse euro and usd values from central bank and save it to a table but result is always zero what can be the problem?

This is the code :

Code: Select all

$file = fopen("http://www.bnro.ro/Ro/Info/", "r");
 
$tarih = date('Y.m.d');
 
$today = date("d-m-Y");
$numeValuta = array("Euro","Dolarul SUA");
while (!feof($file)){
    $line = fgets($file, 1024);
    if (eregi('<TD class="bold">(.*)</TD>', $line, $out))     {
        $cursvalutar = each($out);
        while (list($key,$val) = each($numeValuta)){            
            if ($val == "Euro") {               
                $euro = str_replace(',','.',$cursvalutar[1]);
                }
                if ($val == "Dolarul SUA"){               
                    $dolar = str_replace(',','.',$cursvalutar[1]);
                }
                break;
        }
    }
}
fclose($file);
$sql=mysql_query("select * from currncy where crrn_name='ron' and tarih='$tarih'");
if(mysql_num_rows($sql) == 0) {
mysql_query("INSERT INTO currncy VALUES('','$tarih','ron','$euro')") or die(mysql_error());}
when i print the value on the page by writing

Code: Select all

echo $euro;
It prints the valu without any problem

Note : My field type is decimal(5,2) for this value on the respective table. But parse value is 3.7694 or something like this. may it be reason of the problem?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: I can't get value of parsed variable

Post by Christopher »

It looks like you should to use $key rather than $cursvalutar[1] in your loop.
(#10850)
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: I can't get value of parsed variable

Post by JAM »

> Code forum?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: I can't get value of parsed variable

Post by Chris Corbyn »

Moved to PHP Code.
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: I can't get value of parsed variable

Post by Sindarin »

Code: Select all

$file = fopen("http://www.bnro.ro/Ro/Info/", "r");
Shouldn't this be something like:

$file = fopen("http://www.bnro.ro/Ro/Info/[b]myfile.txt[/b]", "r"); ?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: I can't get value of parsed variable

Post by Zoxive »

Also there Is an XML version of that link.

http://www.bnro.ro/nbrfxrates.xml

I found it by going to the link (http://www.bnro.ro/Ro/Info/).
Post Reply