0

API for Finance Chart?

Hello sir,
I'm try to yahoo chart on web page but I try to use this nothing happen, why?

<?
if ($stock != "") {
?>
<?php
$yahoo_file = fopen ("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgv&e=.csv","r");
$stock_info = fgetcsv ($yahoo_file, 1000, ",")
?>
<b><a href="http://www.jimmyharmon.com/stocks/quotes.php?stock=<?php echo $stock_info[0] ?>"><?php echo $stock_info[0] ?></a></b><dt>
<b>Last: </b>$<?php echo $stock_info[1] ?>&nbsp;&nbsp;<b>Change: </b>

<?php echo "<img src=";
# If we gained print the percentage in GREEN
if ($stock_info[4]>0) {
echo "http://www.jimmyharmon.com/stocks/up.gif";
}

# if we lost RED
elseif ($stock_info[4]<0) {
echo "http://www.jimmyharmon.com/stocks/down.gif";
} # No color
else {
echo "http://www.jimmyharmon.com/images/spacer.gif";
}
echo "> </span></li>\n";
?>

<?php echo "<span style=\"";
# If we gained print the percentage in GREEN
if ($stock_info[4]>0) {
echo "color: #009900;";
} # if we lost RED
elseif ($stock_info[4]<0) {
echo "color: #990000;";
} # No color
else {
echo "font-weight: normal;";
}
echo "\">".$stock_info[4]."</span></li>\n";
?>



<dt>

<?
//Grabs the chart corresponding with the correct stock using the $stock variable
echo("<img width=192 height=96 src=\"http://ichart.yahoo.com/t?s=$stock\"></img><dt>");
?>
<font size="1" face="Verdana"><b><a href="http://finance.yahoo.com/q/bc?s=<? echo($stock); ?>&t=1d" target="_blank">1d</a>
- <a href="http://finance.yahoo.com/q/bc?s=<? echo($stock); ?>&t=5d" target="_blank">5d</a>
-&nbsp;<a href="http://finance.yahoo.com/q/bc?s=<? echo($stock); ?>&t=3m" target="_blank">3m</a>
-&nbsp;<a href="http://finance.yahoo.com/q/bc?s=<? echo($stock); ?>&t=6m" target="_blank">6m</a>
-&nbsp;<a href="http://finance.yahoo.com/q/bc?s=<? echo($stock); ?>&t=1y" target="_blank">1Y</a>
-&nbsp;<a href="http://finance.yahoo.com/q/bc?s=<? echo($stock); ?>&t=5y" target="_blank">5Y</a>
-&nbsp;<a href="http://finance.yahoo.com/q/bc?s=<? echo($stock); ?>&t=my" target="_blank">Max</a></b></font>


<?
} else {
echo"";
} ?>

by
3 Replies
  • Hi Chinmay,

    I would recommend turning on error reporting within PHP - it gives you quite a lot of information about errors you are seeing. Add these two lines of PHP to the top of the scripts:

    CODE
    error_reporting(E_ALL);
    ini_set("display_errors", 1);


    I did that and ran your script and immediately saw the following notice:
    CODE
    Notice: Undefined variable: stock in test.php on line 5


    That will help you to debug your application.

    Jonathan LeBlanc
    Senior Software Engineer
    Yahoo! Developer Network
    Twitter: jcleblanc
    0
  • Isn't it against Yahoo! Finance ToS to display quotes on your webpage?
    0
  • QUOTE (numbflux @ Oct 17 2009, 02:40 PM) <{POST_SNAPBACK}>
    Isn't it against Yahoo! Finance ToS to display quotes on your webpage?
    0

Recent Posts

in PHP Development