/******************************************************** * history.php * Purpose - Retrive the history information of a stock * Author - JackWind, Li Guojie. * Date - 2002.JULY.17 * All Rights Reserved by Li Guojie (liguojie@yahoo.com) *********************************************************/ /*** Params needed. $MODE : 2 - One month; 3 - 3 Month; 4 - six, 5 - One Year. $ID : Stock Code or Short code for SGX. $EX : The exchange which the stock belongs to; ***/ $MODE = $HTTP_GET_VARS['T']; $EX = $HTTP_GET_VARS['E']; $ID = $HTTP_GET_VARS['S']; $ERROR = 0; // 0 - Error // 1 - NO Error $DEBUG = 1; // 0 - Application version. // 1 - Debug Version. if( (!(isset($EX) && isset($ID) && $MODE >= 0)) || empty($ID) ) { // If param not presents. echo $ERROR; exit; } if($MODE == 0) { // Stock validation $FILE; $LINE; $URL = "http://finance.yahoo.com/d/quotes.csv?s=" . $ID . "&f=sl1d1t1c1ohgv&e=.csv"; $FILE = fopen($URL, "r"); $LINE = fgets ($FILE, 2048); // $LINE = eregi_replace("\"", "", $LINE); if(eregi($ID, $LINE)) { $ERROR = 1; }else{ $ERROR = 0; } echo $ERROR; exit; }else if($MODE == 1) { // live information $FILE; $LINE; $REGS; $URL = "http://finance.yahoo.com/d/quotes.csv?s=" . $ID . "&f=sl1d1t1c1ohgv&e=.csv"; $FILE = fopen($URL, "r"); $LINE = fgets ($FILE, 2048); $LINE = eregi_replace("\"", "", $LINE); if(eregi($ID, $LINE)) { $ERROR = 1; }else{ $ERROR = 0; } if( eregi("([0-9]*\.[0-9]*),([0-9]*/[0-9]*/[0-9]*),.*([+-]{1}[0-9]*\.[0-9]*),([0-9]*\.[0-9]*),([0-9]*\.[0-9]*),([0-9]*\.[0-9]*),([0-9]*)", $LINE, $REGS) ) { //echo $REGS[0] . "\n"; echo $ERROR . "*" . ($REGS[1]*1000) . "*" . ($REGS[3]*1000.0) . "*" . ($REGS[4]*1000) . "*" . ($REGS[5]*1000) . "*" . ($REGS[6]*1000) . "*" . $REGS[7] ."*"; }else{ $ERROR = 0; echo $ERROR; } }else{ // Historical data. $fromDay = ""; $fromMonth = ""; $fromYear = ""; if($MODE == 2) { // One month. - BUG HERE! TWO YEARS! if(date("m") == 1) {// across two years! $fromYear = (date("y")-1); // Year $fromMonth = "12"; // Month $fromDay = date("d"); // Day }else{ // Within one year. $fromYear = date("y"); // Year $fromMonth = (date("m") - 1); $fromDay = date("d"); } }else if($MODE == 3) { // Three months if(date("m") <= 3) { // across 2 years. $fromYear = (date("y")-1); // Year $fromMonth = 12 + date("m") - 3; // Month should be >= 10 $fromDay = date("d"); // Day }else{ // within one year. $fromYear = date("y"); // Year. $fromMonth = (date("m") - 3); // Aleawys <= 9; $fromDay = date("d"); } }else if($MODE == 4) { // 6 months. if(date("m") <= 6) { // across two years. $fromYear = (date("y")-1); // Year. $fromMonth = 12 + date("m") - 6; $fromDay = date("d"); }else{ // within one year. $fromYear = date("y"); // Year. $fromMonth = (date("m") - 6); // Aleawys <= 9; $fromDay = date("d"); } }else if($MODE == 5) { // One Year. $fromYear = (date("y")-1); // Year. $fromMonth = date("m"); $fromDay = date("d"); } $URL = "http://table.finance.yahoo.com/table.csv?a=" . $fromMonth . "&b=" . $fromDay . "&c=" . $fromYear . "&s=" . $ID . "&y=0&g=d&ignore=.csv"; $FILE = fopen($URL, "r"); $LINE = fgets ($FILE, 2048); // Skip first line $ERROR = 1; echo $ERROR . "*"; while(! feof($FILE)) { // $LINE = fgets ($FILE, 2048); //echo $LINE . "