topical media & game development

talk show tell print

professional-web-01-v1-yahoo-quotes.php / php



  <?php
  include ('cache.inc');
  
  function get_xml(url) {
    csv = file_get_contents(url, "r");
    a = '"([^"]*)"';
    n = '([^,]*)';
    pattern = "/^a,a,n,a,a,n,n,n,n,n/";
    match = preg_match(pattern, csv, matches);
    xml = new SimpleXMLElement("<quote><symbol/><name/><lastTrade><price/><date/><time/></lastTrade><change/><open/><high/><low/><volume/></quote>");
    xml->symbol = matches[1];
    xml->name = matches[2];
    xml->lastTrade->price = matches[3];
    xml->lastTrade->date = matches[4];
    xml->lastTrade->time = matches[5];
    xml->change = matches[6];
    xml->open = matches[7];
    xml->high = matches[8];
    xml->low = matches[9];
    xml->volume = matches[10];
    return xml->asXML();
  
  }
  
  // See http://www.gummy-stuff.org/Yahoo-data.htm
  send_cached_xml("http://finance.yahoo.com/d/quotes.csv?f=snl1d1t1c1ohgv&e=.csv&s=" . urlencode(_GET['tag']), get_xml, 900);
  ?>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.