Hi guys,
I need help getting a stock ticker running. I’ve found snippets on the web, but can’t finish it… I barely, not even barely know PHP. Please help… :-[
I have this much:
<?php
foreach ($raw_stock_data as $value) {
$results = explode(' ',$value);
$ticker = $results[0];
$buy = $results[1];
$sell = $results[2];
echo "<font color=\"#ffffff\">$ticker </font>";
echo "<font color=\"#00ff00\">$buy </font>";
echo "<font color=\"#ff0000\">$sell </font>";
echo " ";
}
?>
but need to get it to feed information from yahoo finance. I found this to do that part;
<?php // Code by: Don Wilson // Edited: October 24, 2003 class stock { function getLastTrade($symbol) { $file = fopen("http://quote.yahoo.com/d/quotes.csv?s={$symbol}&f=sl1d1t1c1ohgv&e=.csv", "r"); $read = fread($file, 2000); fclose($file); $read = str_replace(""", "", $read); $read = explode(",", $read); return $read[1]; } function getChange($symbol) { $file = fopen("http://quote.yahoo.com/d/quotes.csv?s={$symbol}&f=sl1d1t1c1ohgv&e=.csv", "r"); $read = fread($file, 2000); fclose($file); $read = str_replace(""", "", $read); $read = explode(",", $read); return $read[4]; } function getDateClosed($symbol) { $file = fopen("http://quote.yahoo.com/d/quotes.csv?s={$symbol}&f=sl1d1t1c1ohgv&e=.csv", "r"); $read = fread($file, 2000); fclose($file); $read = str_replace(""", "", $read); $read = explode(",", $read); return $read[2] . " " . $read[3]; } } $stock = new Stock(); echo "\n";
if(isset($symbols))
{
$symbols = explode(",", $symbols);
foreach($symbols as $symbol)
{
$change = $stock->getChange($symbol);
if($change < 0)
$change = "{$change}";
elseif($change > 0)
$change = "{$change}";
else
$change = "0.00";
echo "Symbol: " . $symbol . "\n";
echo "Last Trade: " . $stock->getLastTrade($symbol) . "\n";
echo "Change: " . $change . "\n";
echo "Date Closed: " . $stock->getDateClosed($symbol) . "\n";
echo "\n";
}
}
echo "\n";
?>
But how to properly use part of that information, or even if it can be done has me lost. Can anyone help?
thanks!
YN
