reading a csv file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ashishagarwal
Forum Newbie
Posts: 1
Joined: Tue Feb 08, 2011 12:13 pm

reading a csv file

Post by ashishagarwal »

hi,
i am trying to read a csv file at the location $url using the following code, but it is not able to open the handle... it goes into the else statement and prints "error" ... can any one please help ?


Code: Select all

echo $stock_list;

if (! $stock_list) {
$stock_list = "^IXIC,^DJA,^NIN,^FTSE";
}


$url = "http://quote.yahoo.com/d/quotes.csv?s=" . $stock_list . "&f=nl1c1& =.csv";

echo $url;

$filesize = 2000;

if(($handle = fopen($url, "r"))!=FALSE)
{
echo "\n handle = ";
echo $handle;
$raw_quote_data = fread($handle, $filesize);
echo $raw_quote_data;
echo $url;
fclose($handle);
}
else
{
echo "failure";
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: reading a csv file

Post by John Cartwright »

Firstly, please wrap your code in php tags next time.

Secondly, you always want to have error reporting and display errors elevated enough during development. Try adding

Code: Select all

ini_set('display_errors', 1);
error_reporting(E_ALL);
to the top of your script, and you'll see the errors.

Thirdly,

The configuration that is causing the problem is allow_url_fopen (most likely)
Post Reply