Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts

    Stock and currency quotes from Yahoo Finance

    This PHP script can be used to get real time stock and currency quotes from Yahoo Finance. The example posted will echo the value of $100 US in Canadian dollars.

    The $ticker variable can be currency or stocks. Lots of info can be gathered from this script such as, high/low of the day, open quotes, last trade, time of last trade, volume, etc. Yahoo Finance has all the symbols you need such as RHAT for Red Hat, AAPL for Apple, and all the currency symbols like CADUSD=X for US Dollar and Canadian dollar.

    PHP Code:
    <?php

    $us_price 
    '100';

    $ticker'CADUSD=X';
    $open fopen("http://quote.yahoo.com/d/quotes.csv?s=$ticker&f=sl1d1t1c1ohgv&e=.csv""r");
    $exchange_rate fread($open2000);
    fclose($open);
    $exchange_rate str_replace("\""""$exchange_rate);
    $exchange_rate explode(","$exchange_rate);
    $ca_price = ($us_price/$exchange_rate[1]);
    $price number_format ($ca_price2);

    echo 
    "$us_price US dollars = \$$price Canadian dollars";

    ?>
    Leonard Whistler

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    108
    Thanks
    19
    Thanked 13 Times in 13 Posts
    Could come in handy, thanks.

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Below is a link to a working demo of the PHP stock/currency script customized for a specific currency, in this case the Cuban Convertible Peso (CUC).

    Currency exchange calculator using PHP
    Leonard Whistler

  • #4
    New Coder
    Join Date
    May 2008
    Location
    Sydney, Australia
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Great script Len. Have you tried using it for currency information e.g. http://finance.yahoo.com/q?s=USDEUR=X

  • #5
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's really awesome peace of code!I also like Currency exchange calculator using PHP!Guys I had some ideas of placing something similar to my blog, unfortunately, I am not so knowledgeable in this field as you are
    Last edited by Fou-Lu; 08-27-2010 at 03:16 PM. Reason: Signatures allowed through control panel only

  • #6
    phm
    phm is offline
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hello, can you please tell me how i can make this script work in a webpage?

    i just include it in the webpage? but it doesn't work like that, let me know the details thanks!
    Last edited by phm; 02-26-2012 at 09:17 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •