Yahoo stock quote example

Yahoo stock quote example

//stock quote script
//this is the url for Microsoft’s stock quote , we are opening it for reading
$fp = fopen (“”,”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]–>

<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>

//close the filehandle $fp
fclose ($fp);

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

14 comments to Yahoo stock quote example

  • Mathi

    Warning: fopen( [function.fopen]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\phpEX\feed.php on line 2

    Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\phpEX\feed.php on line 2

    I am getting this error while tried out the above to yahoo quotes. :(

  • admin

    I have tried this in my test PC which is using Xampp and I cannot see an issue I’m afraid. I have a reasonably fast connection and the quotes come in about 1 second maximum time.

    Example output

    description latest figure
    symbol MSFT
    last price 15.90
    date 3/2/2009
    time 1:43pm
    change -0.25
    open 15.95
    high 16.25
    low 15.82
    volume 46050552

  • Ken

    I am glad to find these code that show me how to get the stock data come from web service. However, I would like to know how to send the latest stock price data to the MYSQL database at a period of time as a background process of a website regularly and automatically for further analysis (about 15 min for once time ). Actully, I am the beginner of these field of program. Could you share ideas or hints for me? Thank you for your help!

  • How to get last 30 days data for drawing graph??

  • diyan

    you must make web service or make programe XML very quicly for web

  • pard1

    Thanks.. for the tutorial.. :)

  • Kamal

    I want a program which download 1 minute & 5 minute intraday stock quotes from yahoo finance after market hours. Means I want historical intraday data downloader program which download 1 min & 5 min quotes of multiple stocks in text format. I am ready to pay for program. Thanks- Kamal (

  • Suj

    thanks mate. extremely useful. I just had one issue with the quotes, which I fixed it.

    thanks again.

  • aditya

    please help me also….
    i m getting this error
    Parse error: parse error in D:\wamp\www\practice\ABCD.php on line 4
    please help me to solve this problem.

  • How can we do this for multiple quotes on the same page? And how can I get the P/E up there too?


  • known

    php_network_getaddresses: getaddrinfo failed

    This error is coming
    Wamp server is installed on my computer and i have to use a proxy to connect to the internet

  • dave

    Hello, thanks so much. It works like a charm. My only question is, can I use this code on a commercial financial web-site without violating the terms and conditions regarding the use of yahoo??? Thanks so much. hope to hear from you.

  • Milan

    Great article – Is there a description of all the fields available from yahoo

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=""> <strike> <strong>