<?php
$data= '"CIEL3.SA",35.10,"SAO","+4.71%",+1.58,35.85,34.00,"34.00 - 35.85",8637900,"BRL","3/17/2016","5:08pm"';
$properties=explode(",",$data);
$fields = array('Symbol', 'LastTradePriceOnly', 'StockExchange', 'ChangeinPercent', 'Change', 'DaysHigh', 'DaysLow', 'DaysRange', 'Volume', 'Currency', 'LastTradeDate', 'LastTradeTime');
foreach ($properties as $key=>$value) {
$quotes[] = array (
$fields[$key] => $value
);
};
$results = array (
"query" => array (
"results" => array (
"quote" => $quotes
)
)
);
echo json_encode($results);
$row = 1;
$quotes = null;
$stream = fopen("http://download.finance.yahoo.com/d/quotes.csv?s=CIEL3.SA&f=sl1xp2c1hgmvc4d1t1", "r");
//$stream = fopen('data://text/plain;base64,' . base64_encode($data),'r');
while (($data = fgetcsv($stream, 12, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num campos na linha $row: <br /></p>\n";
$row++;
foreach ($data as $key=>$value) {
$quotes[] = array (
$fields[$key] => $value
);
};
}
$results = array (
"query" => array (
"results" => array (
"quote" => $quotes
)
)
);
echo json_encode($results);
preferences:
51.64 ms | 402 KiB | 5 Q