Page 1 of 1

file_get_contents csv

Posted: Tue Aug 25, 2009 5:15 pm
by flower
I want to read a file from another website by using the function file_get_contents.
The file is a .txt file with csv data, the data is separated by semicolons.
When I open the file with notepad, everything is normal, but when I print it to the screen with php, after it has been read by file_get_contents, the semicolons are gone.
The file:
http://www.euronext.com/search/download ... e=dd/MM/yy

Thanks in advance,
Flower.

Re: file_get_contents csv

Posted: Tue Aug 25, 2009 5:19 pm
by Mark Baker
I know I need to use glasses for reading and screen work, and I'm not wearing them at the moment; but I can see a lot of semi-colons in that file, exactly where I'd expect to see them

Re: file_get_contents csv

Posted: Tue Aug 25, 2009 5:32 pm
by requinix
I think s/he's saying that the semicolons are gone after the PHP works on the file.

Post code.

Re: file_get_contents csv

Posted: Tue Aug 25, 2009 5:41 pm
by flower
Thanks for the quick response.

Code: Select all

 
<?php
 
if(file_get_contents('http://www.euronext.com/search/download/trapridownloadpopup.jcsv?pricesearchresults=actif&filter=1&belongsToList=market_EURLS&lan=NL&mep=8626&resultsTitle=Amsterdam+-+Euronext&cha=1800&totalOfInstruments=195&format=txt&formatDecimal=,&formatDate=dd/MM/yy')) {
    $contents = file_get_contents('http://www.euronext.com/search/download/trapridownloadpopup.jcsv?pricesearchresults=actif&filter=1&belongsToList=market_EURLS&lan=NL&mep=8626&resultsTitle=Amsterdam+-+Euronext&cha=1800&totalOfInstruments=195&format=xls&formatDecimal=,&formatDate=dd/MM/yy');
    $contents_array = explode("\n",$contents);
    $i = 4;
    foreach($contents_array as $value) {
        if($i >= 4) {
            list($company,$ISIN,$Euronext_code,$Market,$Symbol,$ICB_Sector_Level_4,$Handelsvaluta,$Laatst,$Aantal,$percentage,$Datum_tijd,$Omzet,$Totaal_aantal_aandelen,$Capitalisation,$Trading_mode,$Dag_Open,$Dag_Hoog,$Dag_Hoog_Datum_tijd,$Dag_Laag,$Dag_Laag_Datum_tijd) = explode(" ",$value);
        }
        //echo '----'.$company.'----';
        if(strlen($company) > 0) {
            
            $data[$company] = 
            array(
            "ISIN"                  => $ISIN, 
            "Euronext_code"         => $Euronext_code, 
            "Market"                => $Market, 
            "Symbol"                => $Symbol, 
            "ICB_Sector_Level_4"    => $ICB_Sector_Level_4, 
            "Handelsvaluta"         => $Handelsvaluta, 
            "Laatst"                => $Laatst, 
            "Aantal"                => $Aantal, 
            "Percentage"            => $percentage, 
            "Datetime"              => $Datum_tijd,
            "Omzet"                 => $Omzet,
            "Tot aandelen"          => $Totaal_aantal_aandelen,
            "Capitalisation"        => $Capitalisation,
            "Trading_mode"          => $Trading_mode,
            "Dag_Open"              => $Dag_Open,
            "Dag_Hoog"              => $Dag_Hoog,
            "Dag_Hoog_datetime"     => $Dag_Hoog_Datum_tijd,
            "Dag_Laag"              => $Dag_Laag,
            "Dag_Laag_Datum_tijd"   => $Dag_Laag_Datum_tijd
            );
        }
        $i++;
    }
}
 
?>
 

Re: file_get_contents csv

Posted: Tue Aug 25, 2009 5:49 pm
by alex.barylski
When you print to screen the semi-colons are gone? Maybe the browser is interpreting them...dump the contents to a local file and open that file in notepad, are the semi-colons gone?

Re: file_get_contents csv

Posted: Tue Aug 25, 2009 5:51 pm
by flower
Glad you ask..
I already tried, the semicolons are still nowhere to be found.

Re: file_get_contents csv

Posted: Tue Aug 25, 2009 6:23 pm
by requinix
*cough*

There are no semicolons in the CSV. Anywhere.

Check your URLs more carefully ;)

Re: file_get_contents csv

Posted: Wed Aug 26, 2009 4:27 am
by flower
I'm Dutch but when I say semi-colon I mean this thing ;
When I open the link, I posted earlier, in Mozilla Firefox, It asks me to download composition.txt. When I open that file, I see the following:

http://img195.imageshack.us/img195/9396/semicolons.png

It's full of semi-colons, or am I wrong?

Re: file_get_contents csv

Posted: Wed Aug 26, 2009 4:38 am
by yasir_memon

Re: file_get_contents csv

Posted: Wed Aug 26, 2009 5:08 am
by flower
I don't get it, that's the same link?

Re: file_get_contents csv

Posted: Wed Aug 26, 2009 6:11 am
by Eran
why aren't you using fgetcsv()?

Re: file_get_contents csv

Posted: Wed Aug 26, 2009 6:25 am
by flower
Thanks for your reply.
I didn't know fgetcsv() existed. I'm going to try it right now.

Edit:
Thanks, fgetcsv() works perfectly till now!