Hi all,
I'm trying to use PHP to read this:
http://download.finance.yahoo.com/d/quo ... &f=nl1c1&e
The output is this:
"GEN ELECTRIC CO",16.22,+0.06
"Google Inc.",514.18,-3.36
I'm trying to use the explode function to seperate the top from bottom but it keeps bundling them together when I use this:
$csv = @file_get_contents($url);
$quote = explode("\r", $csv) ;
So if I echo $quote[0] it looks like this: "GEN ELECTRIC CO",16.22,+0.06 "Google Inc.",514.18,-3.36
In actual fact, I want
$quote[0] = "GEN ELECTRIC CO",16.22,+0.06
$quote[1] = "Google Inc.",514.18,-3.36
Thanks!
Re: Explode Function - Delimiter issue?
Moderator: General Moderators
Re: Explode Function - Delimiter issue?
If you're on Windows, use \r\n... otherwise, \n...
Re: Explode Function - Delimiter issue?
Using \n in the explode() function will be compatible with both Windows and non-Windows systems. Then use trim($quote[0]) etc. to remove the redundant \r, if present.Mirge wrote:If you're on Windows, use \r\n... otherwise, \n...
EDIT:
On second thoughts, you could do away with the file_get_contents() and just do:
Code: Select all
$quote = @file($url, FILE_IGNORE_NEW_LINES);Re: Explode Function - Delimiter issue?
Thanks to both of you!
The
$quote = @file($url, FILE_IGNORE_NEW_LINES);
works perfectly!
Cheers
The
$quote = @file($url, FILE_IGNORE_NEW_LINES);
works perfectly!
Cheers
Re: Explode Function - Delimiter issue?
Have you heard of fgetcsv?