file_get_contents csv
Moderator: General Moderators
file_get_contents csv
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.
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.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: file_get_contents csv
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
I think s/he's saying that the semicolons are gone after the PHP works on the file.
Post code.
Post code.
Re: file_get_contents csv
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++;
}
}
?>
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: file_get_contents csv
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
Glad you ask..
I already tried, the semicolons are still nowhere to be found.
I already tried, the semicolons are still nowhere to be found.
Re: file_get_contents csv
*cough*
There are no semicolons in the CSV. Anywhere.
Check your URLs more carefully
There are no semicolons in the CSV. Anywhere.
Check your URLs more carefully
Re: file_get_contents csv
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?
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?
-
yasir_memon
- Forum Commoner
- Posts: 48
- Joined: Tue Aug 11, 2009 12:29 am
Re: file_get_contents csv
I don't get it, that's the same link?yasir_memon wrote:http://img195.imageshack.us/img195/9396/semicolons.png
Re: file_get_contents csv
why aren't you using fgetcsv()?
Re: file_get_contents csv
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!
I didn't know fgetcsv() existed. I'm going to try it right now.
Edit:
Thanks, fgetcsv() works perfectly till now!