Your Ad Here

 Navigation
Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Books
Sample Chapters
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links




 Sponsors
 Links
dvd information
gambling sites
finance products
 Downloads
dzphp editor
EasyPHP
mysql_phpgenerator
php-studio-trial
phpdesigner_7_2_5
phpMyAdmin-3.4.3.2
/phptriad2-2-1
phpxedit_321
rapidphp 2011
WampServer2.1d-x64
WampServer2.1e-x32
xampp-win32-1.7.4-VC6-installer
xampplite-win32-1.7.3
 Misc
Webmaster Resources
Only PHP
ScriptSearch.com
Scripts.com - Get the best scripts NOW!
AndreaPHP Programming

Valid XHTML 1.0 Transitional


Valid CSS!


Display yahoo stock quotes from a CSV file


Display yahoo stock quotes from a CSV file

Most stock quote scripts grab the data from Yahoo and parse th erelevant data out , a lesser known feature is that the latest stock quotes are available in a CSV file from yahoo . This script utilises this and displays all of the latest stock information , we think you will agree it is a useful approach to displaying stock quotes on your site .

Code :

<?php
//stock quote script
//this is the url for Microsoft's stock quote , we are opening it for reading
$fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s=msft&f=sl1d1t1c1ohgv&e=.csv","r");
//this uses the fgetcsv function to store the quote info in the array $data
$data = fgetcsv ($fp, 1000, ",")
?>
<!-- this is our table which displays the stock info -->
<!-- we access the individual items by using $data[0]-->
<table>
<tr><td>description</td><td>latest figure</td><tr>
<tr><td>symbol</td><td><?php echo $data[0] ?></td></tr>
<tr><td>last price</td><td><?php echo $data[1] ?></td></tr>
<tr><td>date</td><td><?php echo $data[2] ?></td></tr>
<tr><td>time</td><td><?php echo $data[3] ?></td></tr>
<tr><td>change</td><td><?php echo $data[4] ?></td></tr>
<tr><td>open</td><td><?php echo $data[5] ?></td></tr>
<tr><td>high</td><td><?php echo $data[6] ?></td></tr>
<tr><td>low</td><td><?php echo $data[7] ?></td></tr>
<tr><td>volume</td><td><?php echo $data[8] ?></td></tr>
</table>
<?php
//close the filehandle $fp
fclose ($fp);
?>

Example :


Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in /home/beginne/public_html/yahoocsv.php on line 204

Warning: fopen(http://finance.yahoo.com/d/quotes.csv?s=msft&f=sl1d1t1c1ohgv&e=.csv) [function.fopen]: failed to open stream: no suitable wrapper could be found in /home/beginne/public_html/yahoocsv.php on line 204

Warning: fgetcsv() expects parameter 1 to be resource, boolean given in /home/beginne/public_html/yahoocsv.php on line 206
description latest figure
symbol
last price
date
time
change
open
high
low
volume

Warning: fclose(): supplied argument is not a valid stream resource in /home/beginne/public_html/yahoocsv.php on line 254



Books
 Sponsors


 Random Code
Short urls with Bit.ly(internet)
Simple metatag generator(application)
Java version with php(php and java)
 Random Article
  Network
Programming resources
Tutorials directory
Hosting resources
ASP site
Domain names
Progged
Maxi directory
bigarticle : free articles
A Code
Code N Tutorials
Get PHP
Programmers help




beginners PHP Copyright © 2004 onwards by beginnersPHP.