Php code _ PHP Tutorial for capturing YAHOO stock quotations in real time

Source: Internet
Author: User
Tags ichart
The php code that captures YAHOO stock quotes in real time. FunctiongetYahooQuote ($ stockSymbolCCR) {if (! $ TargetURL) $ targetURLfinance. yahoo. comq? S $ stockSymbol 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 )."";
If (strstr ($ buffer, "rowspan = 3 "))
{
// Echo "extract started at line # $ lineCount ";
$ StartExtract = 1;
}
If ($ startExtract &&! $ StopExtract)
{

If (strstr ($ buffer ,"{
$ StartPos = strrpos ($ buffer, "<");
$ Buffer = substr ($ buffer, $ startPos );
}
// $ Text = trim (strip_tags ($ buffer ));
// Echo trim ($ buffer )."";

$ Buffer = str_replace ("", "", "$ 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 ";
Echo $ capturedHTML;
Break;
}
$ LineCount ++;
}
Fclose ($ fd );
}

// The following is an example of capturing
$ Symbols = array (CCR, IIXL, SAPE, WBVN );
$ SymbolCount = count ($ symbols );
For ($ I = 0; $ I <$ symbolCount; $ I ++)
{
Echo "$ symbols [$ I]
";
GetYahooQuote ("$ symbols [$ I]");
}
?>

Http://www.bkjia.com/PHPjc/532202.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532202.htmlTechArticlefunction getYahooQuote ($ stockSymbol = "CCR") {if (! $ TargetURL) $ targetURL = "http://finance.yahoo.com/q? S = $ stockSymbol // Set the URL target to be crawled $ fd = fopen ("$ targetURL", "r ")...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.