Categories

Subscribe via Email

Enter your email address to subscribe and receive notifications of new content by email.

Yahoo stock chart

This example displays a stock chart from yahoo.com, it uses fopen to get the relevant page and then uses regular expressions to get the chart image from html tags on yahoo’s site.

Note that using this method, any change to the htm on yahoo’s site would affect the script

<?php

//this is the company you wish to lookup
$company = “sun”;
//this is the url from yahoo + the company
$url = “http://finance.yahoo.com/q?s=” . $company . “&d=c&k=c4″;
//open the url and store in $fp
$fp = fopen($url , “r”);
//read 20000 bytes of the file
$readfile = fread($fp , 20000);
//search for the HTML below and store everything in between in $content
$readfile = ereg(“<big>Chart: </big>(.*)Add to My Portfolio</a>” , $readfile, $content);
//display the results in a table
echo “<table width = ‘100%’>”;
echo “$content[1]”;
echo “</table>”;
//close the file handle
fclose($fp);
?>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare

1 comment to Yahoo stock chart

  • Saurabh

    I need to have a quote script which also shows a chart, is it possible?
    What i mean is yur yahoo quote example +Yahoo stock chart.

    I’m making a site on joomla and want to insert quotes in articles.

    Can you kindly help.

    regards
    Saurabh

Leave a Reply

  

  

  


*

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>