Why is the "feof" function terminating to read the file before end of the file?

Hi,

I try to get some data from a web page which includes daily Exchange rates. As far as I understand there are two tables in the web page, I can get the data in the first table, but from the second table there is no data come out. Let me clarify myself; with “feof” and “fgets” functions I can get the data like USD/TRY, AUD/TRY, EUR/TRY. But “feof” terminates to read the file after reading numbers of PKR/TRY, although there are more data on the file such as USD/ AUD, USD/DKK, USD/CHF, … I am using the following script. In my opinion there is no error on the script, but maybe I should use some other function instead of “feof”. :-\ My goal is to get the Cross Rates data such as USD/AUD, EUR/USD. Please help me to solve my problem. Thanks for your help in advance.

$link=fopen(“http://www.tcmb.gov.tr/kurlar/today.xml","r”) or die (“Page Error”);

while (!feof($link)) {
$line1= fgets($link, 4096);
if ($place1=strpos($line1, “EUR/USD”)===false)
{
}
else {
$yer1=strpos($line1,“EUR/USD”);
echo $line1;
$usdavrovalue=substr($line1,$place1,92);

echo $usdavrovalue;

break;
}
}

fclose($link);

As far as understand there is a one xml file in the web page, but more than one sheets in the file. In this point “feof” or “copy” functions can only get the first sheet. However the data which I need are in the second sheet. Is there any one can help me to get the data in the second sheet of the xml file?
:’( :’(

From what I see from the link, there isn’t an XML file there at all, but a HTML file with 3 tables. You could use SimpleXML and you would access the tables by index (0 for the first, 1 for the second, and so on). That is the best advice I can give from the input I see on their page.

Hi,
First of all, thanks for your reply. I am a beginner on php. I try to use simplexml and index functions, but I could not do it. Can you send me a basic php codes to get the second table from the xml pages “http://www.tcmb.gov.tr/kurlar/today.xml” .
Thanks in advance.

I won’t give you code, that will not help you learn. Try the tutorial here

Problem’s solved.

Sponsor our Newsletter | Privacy Policy | Terms of Service