= 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 . "
"; if( eregi("([0-9]*)-([a-zA-Z]*)-([0-9]*),([0-9]*\.[0-9]*),([0-9]*\.[0-9]*),([0-9]*\.[0-9]*),([0-9]*\.[0-9]*),([0-9]*)", $LINE, $REGS) ) { //echo $REGS[0] . "\n"; $thisDay = $REGS[1]; $thisMonth = $REGS[2]; $thisYear = $REGS[3]; $priceHigh = $REGS[5]; $priceLow = $REGS[6]; $volume = $REGS[8]; if($thisMonth == "Jan") { $thisMonth = 1; }else if($thisMonth == "Feb") { $thisMonth = 2; }else if($thisMonth == "Mar") { $thisMonth = 3; }else if($thisMonth == "Apr") { $thisMonth = 4; }else if($thisMonth == "May") { $thisMonth = 5; }else if($thisMonth == "Jun") { $thisMonth = 6; }else if($thisMonth == "Jul") { $thisMonth = 7; }else if($thisMonth == "Aug") { $thisMonth = 8; }else if($thisMonth == "Sep") { $thisMonth = 9; }else if($thisMonth == "Oct") { $thisMonth = 10; }else if($thisMonth == "Nov") { $thisMonth = 11; }else if($thisMonth == "Dec") { $thisMonth = 12; } echo ($thisYear+0) . "-" . ($thisMonth+0) . "-" . ($thisDay+0) . " " . ($priceHigh*1000) . " " . ($priceLow*1000) . " " . $volume . "*"; } } // End loop while. }