Code for capturing YAHOO stock quotes in real time .? FunctiongetYahooQuote ($ stockSymbolCCR) {if (! $ TargetURL) $ targetURLfinance. yahoo. comq? S $ stockSymbolquot; set the URL target to be crawled $ fdfopen ($ targetURL, r) Function getYahooQuote ($ stockSymbol = "CCR ")
{
If (! $ TargetURL) $ targetURL = "http://finance.yahoo.com/q? S = $ stockSymbol & d = t "; // Set the URL target to be crawled
$ Fd = fopen ("$ targetURL", "r ");
$ StopExtract = 0;
$ StartExtract = 0;
While (! Feof ($ fd ))
{
$ Buffer = fgets ($ fd, 4096 );
// Echo trim ($ buffer). "\ n ";
If (strstr ($ buffer, "rowspan = 3 "))
{
// Echo "extract started at line # $ lineCount \ n ";
$ StartExtract = 1;
}
If ($ startExtract &&! $ StopExtract)
{
If (strstr ($ buffer ,"{
$ StartPos = strrpos ($ buffer, "<");
$ Buffer = substr ($ buffer, $ startPos );
}
// $ Text = trim (strip_tags ($ buffer ));
// Echo trim ($ buffer). "\ n ";
$ Buffer = str_replace ("\ n \ r", "", "$ buffer ");
If (strstr ($ buffer, "http://ichart.yahoo.com/v? S = $ stockSymbol "))
{
// Echo "ichart found! ";
$ StopExtract = 1;
}
$ CapturedHTML. = $ buffer;
}
If ($ startExtract & strstr ($ buffer ,"
"))
{
$ StopExtract = 1;
// Echo "extract stopped at line # $ lineCount \ n ";
Echo $ capturedHTML;
Break;
}
$ LineCount ++;
}
Fclose ($ fd );
}
// The following is an example of capturing
$ Symbols = array ('cca', 'iixl ', 'Sape', 'wbvn ');
$ SymbolCount = count ($ symbols );
For ($ I = 0; $ I <$ symbolCount; $ I ++)
{
Echo "$ symbols [$ I]
";
GetYahooQuote ("$ symbols [$ I]");
}
?>
Http://www.bkjia.com/PHPjc/316198.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/316198.htmlTechArticle? Function getYahooQuote ($ stockSymbol = CCR) {if (! $ TargetURL) $ targetURL = http://finance.yahoo.com/q? S = $ stockSymbolquot; // Set the URL target to be crawled $ fd = fopen ($ targetURL, r )...