Page 1 of 1

reading a csv file

Posted: Tue Feb 08, 2011 12:19 pm
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";
}

Re: reading a csv file

Posted: Tue Feb 08, 2011 1:48 pm
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)