Belleanme Posted June 10, 2010 Share Posted June 10, 2010 A client requested a stock ticker on his site. I found this code, which works fine: <?php ///// Replace with Yahoo Finance stock quotes of your choice ////// $raw_stock_data = array('AAPL 200 205', 'BIDU 500 510','RIMM 150 155', 'SNDK 70 72', 'GOOG 500 510','MSFT 30 32','AMD 9 10'); sort($raw_stock_data); ////////////////////////////////////////////////////////////////////////// ?> <div align="center"> <marquee bgcolor="#e0e1e1" direction="left" loop="20" width="100%%"> <?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 " "; } ?> Now, I need to get it to feed live data from the free Yahoo stock info online. I looked for days and finally found this code: <?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 "<pre>\n"; if(isset($symbols)) { $symbols = explode(",", $symbols); foreach($symbols as $symbol) { $change = $stock->getChange($symbol); if($change < 0) $change = "<font color=red>{$change}</font>"; elseif($change > 0) $change = "<font color=green>{$change}</font>"; 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 "</pre>\n"; ?> ...that a nice person kindly shared. I need to integrate the two. What the client wants is just basic stocks, (the ones there listed are fine) and the high and low amount for the day. Can someone please help? I'd be so appreciative! Quote Link to comment https://forums.phpfreaks.com/topic/204435-stock-ticker-help/ Share on other sites More sharing options...
Belleanme Posted June 10, 2010 Author Share Posted June 10, 2010 I am trying to delete this second entry... Quote Link to comment https://forums.phpfreaks.com/topic/204435-stock-ticker-help/#findComment-1070554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.