BTW, I really like your login script I searched the internet for hours trying to find one that would fit my needs, and yours is by far the best. Thanks.
- Code: Select all
<?php
/* Class. */
Class yahoo
{
/* Function. */
function get_stock_quote($symbol)
{
// Yahoo! Finance URL to fetch the CSV data.
$url = sprintf("http://finance.yahoo.com/d/quotes.csv?s=$symbol&f=sl1d1t1c1ohgv&e=.csv", $symbol);
$fp = fopen($url, 'r');
if (!fp) {
echo 'Error : cannot recieve stock quote data.';
} else {
$data = @fgetcsv($fp, 4096, ', ');
fclose($fp);
$this->symbol = $data[0]; // Stock symbol.
//$this->last = $data[1]; // Last Trade (current price).
//$this->date = $data[2];
//$this->time = $data[3];
$this->change = $data[4]; // + or - amount change.
//$this->open = $data[5];
//$this->high = $data[6];
//$this->low = $data[7];
//$this->volume = $data[8];
}
}
}
// Stock symbols.
$symbols = array('^DJI','^IXIC','^GSPC', '^N225','^FTSE');
$i = 0;
// Declare class.
$quote = new yahoo; // new stock.
// Loop thru array of symbols.
foreach ($symbols as $symbol) {
$quote->get_stock_quote($symbols[$i++]); // Pass the Company's symbol.
echo $quote->symbol; // can use $quote->symbol or $symbom
echo ' <span style="';
/* Make the + or - change elicit differing coloration. */
$str = $quote->change;
$first = $str{0};
if ($first == '+') { // If we gained print the # in GREEN.
echo 'color:#009900;';
} elseif ($first == '-') { // If we lost RED.
echo 'color:#990000;';
} else { // NO color.
echo 'font-weight:normal;';
} // endelseif
echo "\">" .$quote->change. "</span></li>\n";
} // endforeach
?>
