Page 1 of 1

I can't get value of parsed variable

Posted: Mon Jan 28, 2008 3:48 am
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?

Re: I can't get value of parsed variable

Posted: Mon Jan 28, 2008 5:06 am
by Christopher
It looks like you should to use $key rather than $cursvalutar[1] in your loop.

Re: I can't get value of parsed variable

Posted: Mon Jan 28, 2008 5:17 am
by JAM
> Code forum?

Re: I can't get value of parsed variable

Posted: Mon Jan 28, 2008 5:35 am
by Chris Corbyn
Moved to PHP Code.

Re: I can't get value of parsed variable

Posted: Mon Jan 28, 2008 7:01 am
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"); ?

Re: I can't get value of parsed variable

Posted: Mon Jan 28, 2008 8:31 am
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/).