- fgetcsv: documentation ( source)
- strtotime: documentation ( source)
- json_encode: documentation ( source)
- fclose: documentation ( source)
- fopen: documentation ( source)
<?php
$arrCSV = array();
//if (($handle = fopen("http://ichart.finance.yahoo.com/table.csv?s=AAPL&d=7&e=7&f=2012&g=d&a=8&b=7&c=1984&ignore=.csv", "r")) !==FALSE)
if (($handle = fopen("http://ichart.finance.yahoo.com/table.csv?s=AAPL", "r")) !==FALSE)
{
$key = 0;
while (($data = fgetcsv($handle, 0, ",")) !==FALSE) {
//echo '<br/>======<br/>';
//print_r($data);
$c = count($data);
If ($key != 0) {
$arrCSV[$key-1][0] = strtotime($data[0])*1000; //Time
$arrCSV[$key-1][1] = floatval($data[1]); //Open
$arrCSV[$key-1][2] = floatval($data[2]); //High
$arrCSV[$key-1][3] = floatval($data[3]); //Low
$arrCSV[$key-1][4] = floatval($data[6]); //Adj Close
$arrCSV[$key-1][5] = floatval($data[5]); //Volume
}
//echo '<Br/>';
//print_r($arrCSV[$key-1]);
$key++;
} // end while
$keymax = $key;
fclose($handle);
} // end if
echo json_encode($arrCSV);
?>