Yahoo Stock Quotes Script

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
rogersjr
Forum Newbie
Posts: 1
Joined: Tue Feb 08, 2011 4:19 pm

Yahoo Stock Quotes Script

Post by rogersjr »

I use a very basic stock quotes script adapted fromwww.suite101.com/content/accessing-yahoo-finance-from-php-a72752

The script is used to import share prices from yahoo and displaying these on a webpage at at http://www.johnrogers.com.au/quotes3.php
I then import this information into a lotus spreadsheet.

The script works quite well except that the table displays twice.

I should add that I do not really understand php scripting. Any help in solving the above problem would be greatly appreciated. The script is as follows:-

Code: Select all

<?php
function show_stock_quotes ($stock_list) {
if (! $stock_list) {
$stock_list = "CEY.AX,DOW.AX,ELD.AX,OZL.AX,SUL.AX,CCV.AX";
}
$url = "http://quote.yahoo.com/d/quotes.csv?s="
. $stock_list . "&f=sl1c1&e=.csv";
$filesize = 2000;
$handle = fopen($url, "r");
$raw_quote_data = fread($handle, $filesize);
fclose($handle);
$quote_array = explode("\n", $raw_quote_data);

echo "<table border=1>";
echo "<th>Company</th> <th>Price</th> <th>Change</th>";
echo "</tr>";

foreach ($quote_array as $quote_value) {
echo "<tr>";
$quote = explode(",", $quote_value);
$symbol = str_replace("\"", "", $quote[0]);
$value = $quote[1];
$change = $quote[2];


echo "<td>$symbol</td> <td>$value</td> <td>$change</td>";
echo "</tr>";

}
echo "</table>";
}
?>


<?php
$symbol_list = str_replace("\n", ",", $_REQUEST["symbol_list"]);
$symbol_list = str_replace("\r", ",", $symbol_list);
show_stock_quotes (False);
show_stock_quotes ($symbol_list);
?>
Last edited by Benjamin on Tue Feb 08, 2011 10:05 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
Post Reply