Here is a function to get stock quote information from yahoo:
function getquote($symbol)
{
if (empty($symbol)) {
$symbol = '^dji';
}
$fields = 'sl1d1t1c1ohgv';
// we use yahoo to get the quotes
//http://download.finance.yahoo.com/d/quotes.csv?s=%5EDJI&f=sl1d1t1c1ohgv&e=.csv
$host = 'http://download.finance.yahoo.com';
// construct the url
$url = $host . '/d/quotes.csv?s='. urlencode($symbol) .'&f='.$fields.'&e=.csv';
// ask yahoo for the .csv file
$csv = fopen($url, "r");
$data = fgetcsv($csv,10000,",");
return $data;
}
How to use the above function:
Forst of all include the above function in your script then for the symbol you want to watch the stock information use it:
for ex:
for symbol ^DJI:
$data = getquote("^DJI");
It will return an array of data in below form:
$data[0]= symbol.
$data[1]= lastprice
$data[2]= date
$data[3]= time
$data[4]= change
$data[5]= open
$datat[6]= high
$data[7]= low
$data[8]= volume
So you can now echo them to get the desired information.
I hopw it will be useful.
Leave a reply