PHP: Building A Stock Index Using Yahoo Finance [on hold]
- by Jeremy
I have the following code which is pulling data but it is not outputting properly.
<?php
class YahooStock {
public function getQuotes(){
$stocks = array();
$result = array();
$s = file_get_contents("http://finance.yahoo.com/d/quotes.csv?s=AMZN+CRM+CNQR+CTL+CTXS+DWRE+EMC+GOOG+HP+IBM+JIVE+LNKD+MKTO+MSFT+N+NFLX+NOW+ORCL+RAX+SAP+T+VEEV+VMW+VZ+WDAY&f=npf6&e=.csv");
$data = explode( ',', $s);
$result = $data;
return $result;
}
}
$objYahooStock = new YahooStock;
foreach( $objYahooStock->getQuotes() as $code => $result){
echo 'Name:' . $result[0] . '<br />';
echo 'Price:' . $result[1] . '<br />';
echo 'Float:' . $result[2] . '<br />';
}
?>
The output looks like it is separating every character with a comma instead of each column:
Name:"
Price:A
Float:m
Name:
Price:I
Float:n
Name:3
Price:3
Float:2
Name:
Price:
Float:
Any help is appreciated!